私はbisonのxフォーマットの文法を考え出そうとしています(実際にはblender pythonスクリプトがエクスポートするサブセットのサブセットです)しかし、シフトリデュースの競合が発生し、Bisonはどこにあるのか、または「一種の」は、私が何をしようとしているかに応じて、どこにあるかを教えてくれます。
まず、blenderのサンプル.xファイルを次に示します。これは私がテストしているものです。
xof 0303txt 0032
Frame Root {
FrameTransformMatrix {
1.000000, 0.000000, 0.000000, 0.000000,
0.000000, 0.000000, 1.000000, 0.000000,
0.000000, 1.000000,-0.000000, 0.000000,
0.000000, 0.000000, 0.000000, 1.000000;;
}
Frame Cube {
FrameTransformMatrix {
1.000000, 0.000000, 0.000000, 0.000000,
0.000000, 1.000000, 0.000000, 0.000000,
0.000000, 0.000000, 1.000000, 0.000000,
0.000000, 0.000000, 0.000000, 1.000000;;
}
Mesh { //Cube_002 Mesh
36;
-1.000000;-1.000000;-1.000000;,
1.000000;-1.000000;-1.000000;,
1.000000; 1.000000;-1.000000;,
0.999999;-1.000001; 1.000000;,
-1.000000; 1.000000; 1.000000;,
1.000000; 0.999999; 1.000000;,
1.000000;-1.000000;-1.000000;,
1.000000; 0.999999; 1.000000;,
1.000000; 1.000000;-1.000000;,
-1.000000;-1.000000;-1.000000;,
0.999999;-1.000001; 1.000000;,
1.000000;-1.000000;-1.000000;,
-1.000000; 1.000000; 1.000000;,
-1.000000;-1.000000; 1.000000;,
-1.000000;-1.000000;-1.000000;,
-1.000000; 1.000000;-1.000000;,
1.000000; 1.000000;-1.000000;,
1.000000; 0.999999; 1.000000;,
-1.000000;-1.000000;-1.000000;,
1.000000; 1.000000;-1.000000;,
-1.000000; 1.000000;-1.000000;,
0.999999;-1.000001; 1.000000;,
-1.000000;-1.000000; 1.000000;,
-1.000000; 1.000000; 1.000000;,
1.000000;-1.000000;-1.000000;,
0.999999;-1.000001; 1.000000;,
1.000000; 0.999999; 1.000000;,
-1.000000;-1.000000;-1.000000;,
-1.000000;-1.000000; 1.000000;,
0.999999;-1.000001; 1.000000;,
-1.000000; 1.000000; 1.000000;,
-1.000000;-1.000000;-1.000000;,
-1.000000; 1.000000;-1.000000;,
-1.000000; 1.000000;-1.000000;,
1.000000; 0.999999; 1.000000;,
-1.000000; 1.000000; 1.000000;;
12;
3;0;1;2;,
3;3;4;5;,
3;6;7;8;,
3;9;10;11;,
3;12;13;14;,
3;15;16;17;,
3;18;19;20;,
3;21;22;23;,
3;24;25;26;,
3;27;28;29;,
3;30;31;32;,
3;33;34;35;;
MeshNormals { //Cube_002 Normals
36;
0.000000; 0.000000;-1.000000;,
0.000000; 0.000000;-1.000000;,
0.000000; 0.000000;-1.000000;,
-0.000000;-0.000000; 1.000000;,
-0.000000;-0.000000; 1.000000;,
-0.000000;-0.000000; 1.000000;,
1.000000; 0.000000;-0.000000;,
1.000000; 0.000000;-0.000000;,
1.000000; 0.000000;-0.000000;,
-0.000000;-1.000000;-0.000000;,
-0.000000;-1.000000;-0.000000;,
-0.000000;-1.000000;-0.000000;,
-1.000000; 0.000000;-0.000000;,
-1.000000; 0.000000;-0.000000;,
-1.000000; 0.000000;-0.000000;,
0.000000; 1.000000; 0.000000;,
0.000000; 1.000000; 0.000000;,
0.000000; 1.000000; 0.000000;,
0.000000; 0.000000;-1.000000;,
0.000000; 0.000000;-1.000000;,
0.000000; 0.000000;-1.000000;,
0.000000;-0.000000; 1.000000;,
0.000000;-0.000000; 1.000000;,
0.000000;-0.000000; 1.000000;,
1.000000;-0.000001; 0.000000;,
1.000000;-0.000001; 0.000000;,
1.000000;-0.000001; 0.000000;,
-0.000000;-1.000000; 0.000000;,
-0.000000;-1.000000; 0.000000;,
-0.000000;-1.000000; 0.000000;,
-1.000000; 0.000000;-0.000000;,
-1.000000; 0.000000;-0.000000;,
-1.000000; 0.000000;-0.000000;,
0.000000; 1.000000; 0.000000;,
0.000000; 1.000000; 0.000000;,
0.000000; 1.000000; 0.000000;;
12;
3;0;1;2;,
3;3;4;5;,
3;6;7;8;,
3;9;10;11;,
3;12;13;14;,
3;15;16;17;,
3;18;19;20;,
3;21;22;23;,
3;24;25;26;,
3;27;28;29;,
3;30;31;32;,
3;33;34;35;;
} //End of Cube_002 Normals
MeshMaterialList { //Cube_002 Material List
1;
12;
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0;;
Material Material {
0.640000; 0.640000; 0.640000; 1.000000;;
96.078431;
0.500000; 0.500000; 0.500000;;
0.000000; 0.000000; 0.000000;;
}
} //End of Cube_002 Material List
} //End of Cube_002 Mesh
} //End of Cube
} //End of Root Frame
そして、ここに文法をキャプチャする2つの試みがあります:
これで、私は得ます:../XGrammar.y: conflicts: 1 shift/reduce
//----------------------------------------------------
Start
: KEYWORD ID '{' EntityDeclaration '}' END
;
//----------------------------------------------------
EntityDeclaration
: KEYWORD ID '{'AttributeDeclaration'}' EntityDeclaration
| KEYWORD ID '{'AttributeDeclaration'}'
;
//----------------------------------------------------
AttributeDeclaration
: KEYWORD '{' Statement AttributeDeclaration '}' AttributeDeclaration
| KEYWORD '{' Statement '}' AttributeDeclaration
| KEYWORD '{' Statement AttributeDeclaration '}'
| KEYWORD '{' Statement '}'
;
//----------------------------------------------------
Statement
: ExpressionList ';'
| ExpressionList ';' Statement
;
//----------------------------------------------------
ExpressionList
: Expression
| Expression ',' ExpressionList
;
//----------------------------------------------------
Expression
: INTEGER
| REAL
| VecFType
;
//----------------------------------------------------
VecFType
: Vec3FType
| Vec4FType
;
//----------------------------------------------------
Vec3FType
: REAL ';' REAL ';' REAL ';'
;
//----------------------------------------------------
Vec4FType
: REAL ';' REAL ';' REAL ';' REAL ';'
;
そして次は、次のようになります。
../XGrammar.y: conflicts: 1 shift/reduce, 2 reduce/reduce
../XGrammar.y:56.3-9: warning: rule never reduced because of conflicts: Expression: Element
//----------------------------------------------------
Start
: KEYWORD ID '{' EntityDeclaration '}' END
;
//----------------------------------------------------
EntityDeclaration
: KEYWORD ID '{'AttributeDeclaration'}' EntityDeclaration
| KEYWORD ID '{'AttributeDeclaration'}'
;
//----------------------------------------------------
AttributeDeclaration
: KEYWORD '{' Statement AttributeDeclaration '}' AttributeDeclaration
| KEYWORD '{' Statement '}' AttributeDeclaration
| KEYWORD '{' Statement AttributeDeclaration '}'
| KEYWORD '{' Statement '}'
;
//----------------------------------------------------
Statement
: Expression ';'
| Expression ';' Statement
;
//----------------------------------------------------
Expression
: Container
| Element
;
//----------------------------------------------------
Container
: VecFType
| ArrayType
;
//----------------------------------------------------
ArrayType
: ';'
| Element ArrayElement
;
//----------------------------------------------------
ArrayElement
: ArrayType
| ','Element ArrayElement
;
//----------------------------------------------------
Element
: INTEGER
| REAL
;
//----------------------------------------------------
VecFType
: ';'
| Element VecElement
;
VecElement
: VecFType
| ';'Element VecElement
;
私は文法が非常に錆びています(大学からしばらく経ちました)が、Microsoftが「コンテナ」の概念をやめ、コンマとセミコロンを混ぜることを決めた素晴らしい方法に関係しているのではないかと思います。http ://msdn.microsoft.com/en-us/library/windows/desktop/bb206298(v=vs.85).aspx
基本的に、コンテナは一種の「暗黙的」であり、その終わりはセミコロンでマークされていると彼らは言います。これは、配列の終わりをマークする方法でもあり、配列のコンテキストで暗黙のコンテナーの(明らかに)個々の要素をマークする方法でもあります...:Sつまり、全体はたわごと。
最初は、このx形式はLR(1)ではありません。
しかし、すぐに、そしてマイクロソフトのドキュメントを読み直した後、私はそのベクトルと配列の全体がbs ...であると思いました(私の文法によるこれらのタイプの違いの私の解釈)。だから、代わりに「コンテナ」の作品を作ればいいなと思いました。次のようなものがあります。ブレースセクション内には、独立型/範囲内/ローカル/whathaveyouのものと含まれているものの2種類の宣言があります。含まれているものは他のものと同じタイプですが、コンテナを「閉じる」ために最後に余分なセミコロンを取ります。しかし、Microsoftのドキュメントを見ると、必ずしもそのようになっているとは限らないことがわかります。
私が得る3番目のアプローチ:
../XGrammar.y: conflicts: 4 shift/reduce, 1 reduce/reduce
../XGrammar.y:61.3-29: warning: rule never reduced because of conflicts: ContainerType: ',' Statement ContainerType
//----------------------------------------------------
Start
: KEYWORD ID '{' Entity '}' END
;
//----------------------------------------------------
Entity
: KEYWORD ID '{'Attribute'}' Entity
| KEYWORD ID '{'Attribute'}'
;
//----------------------------------------------------
Attribute
: KEYWORD '{' Statement Attribute '}' Attribute
| KEYWORD '{' Statement '}' Attribute
| KEYWORD '{' Statement Attribute '}'
| KEYWORD '{' Statement '}'
;
//----------------------------------------------------
Statement
: Declaration ';'
| Declaration ';' Statement
;
Declaration
: ElementType
| ContainerType
;
ContainerType
: Statement ',' Statement
| ',' Statement ContainerType
;
//----------------------------------------------------
ElementType
: INTEGER
| REAL
;
//----------------------------------------------------
だから私は迷子になりました。助けていただければ幸いです。