glpk パッケージから GNU MathProg 言語の文法を作成しようとしていますhttps://www3.nd.edu/~jeff/mathprog/glpk-4.47/doc/gmpl.pdf
残念ながら、これまでに書いた文法はあいまいです。識別子が使用されているときに、解析ツリーのどのブランチが正しいかを bison に伝える方法がわかりません。例えば:
numericExpression : numericLiteral
| identifier
| numericFunctionReference
| iteratedNumericExpression
| conditionalNumericExpression
| '(' numericExpression ')' %prec PARENTH
| '-' numericExpression %prec UNARY
| '+' numericExpression %prec UNARY
| numericExpression binaryArithmeticOperator numericExpression
;
symbolicExpression : stringLiteral
| symbolicFunctionReference
| identifier
| conditionalSymbolicExpression
| '(' symbolicExpression ')' %prec PARENTH
| symbolicExpression '&' symbolicExpression
;
indexingExpression : '{' indexingEntries '}'
| '{' indexingEntries ':' logicalExpression '}'
;
setExpression : literalSet
| identifier
| aritmeticSet
| indexingExpression
| iteratedSetExpression
| conditionalSetExpression
| '(' setExpression ')' %prec PARENTH
| setExpression setOperator setExpression
;
numericLiteral : INT
| FLT
;
linearExpression : identifier
| iteratedLinearExpression
| conditionalLinearExpression
| '(' linearExpression ')' %prec PARENTH
| '-' linearExpression %prec UNARY
| '+' linearExpression %prec UNARY
| linearExpression '+' linearExpression
| linearExpression '-' linearExpression
| linearExpression '*' numericExpression
| numericExpression '*' linearExpression
| linearExpression '/' numericExpression
;
logicalExpression : numericExpression
| relationalExpression
| iteratedLogicalExpression
| '(' logicalExpression ')' %prec PARENTH
| NOT logicalExpression %prec NEG
| logicalExpression AND logicalExpression
| logicalExpression OR logicalExpression
;
identifier : SYMBOLIC_NAME
| SYMBOLIC_NAME '[' listOfIndices ']'
;
listOfIndices : SYMBOLIC_NAME
| listOfIndices ',' SYMBOLIC_NAME
;
識別子は単に「変数」の名前です。変数には特定のタイプ (パラメーター、セット、決定変数) があり、インデックスが付けられている場合があります。コードプログラマーは、たとえば次のようなステートメントで変数の型を宣言する必要があります。
param p1;
param p2{1, 2} >=0;
set s1;
set s2{i in 1..5};
var v1 >=0;
var v2{S1,S2};
しかし、バイソンが識別子を見ると、どのルールを使用すべきかわからず、次のような削減/削減の競合が発生します
113 numericExpression: identifier .
123 symbolicExpression: identifier .
'&' reduce using rule 123 (symbolicExpression)
ELSE reduce using rule 113 (numericExpression)
ELSE [reduce using rule 123 (symbolicExpression)]
INTEGER reduce using rule 113 (numericExpression)
INTEGER [reduce using rule 123 (symbolicExpression)]
BINARY reduce using rule 113 (numericExpression)
BINARY [reduce using rule 123 (symbolicExpression)]
ASIGN reduce using rule 113 (numericExpression)
ASIGN [reduce using rule 123 (symbolicExpression)]
',' reduce using rule 113 (numericExpression)
',' [reduce using rule 123 (symbolicExpression)]
'>' reduce using rule 113 (numericExpression)
'>' [reduce using rule 123 (symbolicExpression)]
'}' reduce using rule 113 (numericExpression)
'}' [reduce using rule 123 (symbolicExpression)]
113 numericExpression: identifier .
123 symbolicExpression: identifier .
130 setExpression: identifier .
UNION reduce using rule 130 (setExpression)
DIFF reduce using rule 130 (setExpression)
SYMDIFF reduce using rule 130 (setExpression)
ELSE reduce using rule 113 (numericExpression)
ELSE [reduce using rule 123 (symbolicExpression)]
ELSE [reduce using rule 130 (setExpression)]
WITHIN reduce using rule 130 (setExpression)
IN reduce using rule 113 (numericExpression)
IN [reduce using rule 123 (symbolicExpression)]
他にも問題がありますが、これは私にとってブロッカーです