我正在尝试从 glpk 包https://www3.nd.edu/~jeff/mathprog/glpk-4.47/doc/gmpl.pdf
为 GNU MathProg 语言创建语法
不幸的是,到目前为止我写的语法是模棱两可的。当使用某些标识符时,我不知道如何告诉野牛解析树的哪个分支是正确的。例如:
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)]
我还有其他问题,但这对我来说是个障碍