我正在使用 Irony 解析 DSL,它具有可以与 AND 和 OR 组合的表达式:
/* snip */
RegisterOperators(4, orKeyword);
RegisterOperators(5, andKeyword);
RegisterOperators(9, lessThanOperator, lessEqualOperator, equalOperator, notEqualOperator, moreThanOperator, moreEqualOperator);
infixOperator.Rule = andKeyword | orKeyword;
expression_in_parens.Rule = L_PAR + expression + R_PAR;
primaryExpression.Rule = expression_in_parens | methodCall | identifier | numberIdentifier | stringIdentifier;
unaryExpression.Rule = notKeyword + L_PAR + expression + R_PAR;
binaryExpression.Rule = expression + infixOperator + expression;
compareExpression.Rule = expression + compareOperator + expression + ReduceHere();
expression.Rule = primaryExpression | unaryExpression | compareExpression | binaryExpression;
我有以下表达式:“A and (B and C or D)”。它被解析为“A and (B and (C or D))”,但我需要它是“A and ((B and C) or D)”。
我认为将 and 关键字注册为具有比 or 关键字更高优先级的运算符会这样做。我错过了什么?