如何在bison语法中正确设置i%2==0的格式?

如何在bison语法中正确设置i%2==0的格式?,bison,Bison,我的语法包含: expression : NUMBER { $$ = new Int($1); } | identifier { $$ = $<expr>1; } | INC identifier { $$ = new UnaryOperation($<expr>2, O_ADD_BEFORE); } | identifier INC { $$ = new UnaryOperation($<expr>1, O_ADD_

我的语法包含:

expression : NUMBER { $$ = new Int($1); }
       | identifier { $$ = $<expr>1; }
       | INC identifier { $$ = new UnaryOperation($<expr>2, O_ADD_BEFORE); }
       | identifier INC { $$ = new UnaryOperation($<expr>1, O_ADD_AFTER); }
       | DEC identifier { $$ = new UnaryOperation($<expr>2, O_SUB_BEFORE); }
       | identifier DEC { $$ = new UnaryOperation($<expr>1, O_SUB_AFTER); }
       | PLUS expression { $$ = $<expr>1; }
       | MINUS expression { $$ = new UnaryOperation($<expr>2, O_UNARY_MINUS); }
       | LNEG expression { $$ = new UnaryOperation($<expr>2, O_LOG_NEG); }
       | BNEG expression { $$ = new UnaryOperation($<expr>2, O_BIT_NEG); }
       | expression PLUS expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_PLUS); }
       | expression MINUS expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_MINUS); }
       | expression MUL expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_MUL); }
       | expression DIV expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_DIV); }
       | expression SHIFTL expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_SHIFT_LEFT); }
       | expression SHIFTR expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_SHIFT_RIGHT); }
       | expression LESS expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_LESS); }
       | expression MORE expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_MORE); }
       | expression LESS_EQ expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_LESS_EQ); }
       | expression MORE_EQ expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_MORE_EQ); }
       | expression BAND expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_BIT_AND); }
       | expression BOR expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_BIT_OR); }
       | expression BXOR expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_BIT_XOR); }
       | expression EQ expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_EQUALS); }
       | expression NEQ expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_NEQUALS); }
       | expression OR expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_LOG_OR); }
       | expression AND expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_LOG_AND); }
       | expression MOD expression { $$ = new BinaryOperation($<expr>1, $<expr>3, O_MOD); }
       | LEFT_BRACE set_expr RIGHT_BRACE { $$ = $<expr>1; }
       | LEFT_BRACE identifier SET_MUL expression RIGHT_BRACE { $$ = new BinaryOperation($<expr>2, $<expr>4, O_SET_MUL); }
       | LEFT_BRACE identifier SET_DIV expression RIGHT_BRACE { $$ = new BinaryOperation($<expr>2, $<expr>4, O_SET_DIV); }
       | LEFT_BRACE identifier SET_MOD expression RIGHT_BRACE { $$ = new BinaryOperation($<expr>2, $<expr>4, O_SET_MOD); }
       | LEFT_BRACE identifier SET_ADD expression RIGHT_BRACE { $$ = new BinaryOperation($<expr>2, $<expr>4, O_SET_ADD); }
       | LEFT_BRACE identifier SET_SUB expression RIGHT_BRACE { $$ = new BinaryOperation($<expr>2, $<expr>4, O_SET_SUB); }
       | LEFT_BRACE identifier SET_SHIFT_L expression RIGHT_BRACE { $$ = new BinaryOperation($<expr>2, $<expr>4, O_SET_SHIFT_L); }
       | LEFT_BRACE identifier SET_SHIFT_R expression RIGHT_BRACE { $$ = new BinaryOperation($<expr>2, $<expr>4, O_SET_SHIFT_R); }
       | LEFT_BRACE identifier SET_AND expression RIGHT_BRACE { $$ = new BinaryOperation($<expr>2, $<expr>4, O_SET_AND); }
       | LEFT_BRACE identifier SET_XOR expression RIGHT_BRACE { $$ = new BinaryOperation($<expr>2, $<expr>4, O_SET_XOR); }
       | LEFT_BRACE identifier SET_OR expression RIGHT_BRACE { $$ = new BinaryOperation($<expr>2, $<expr>4, O_SET_OR); }
       | LEFT_BRACE expression RIGHT_BRACE { $$ = $2; }
       ;
将以以下操作顺序结束:

PUSH i
PUSH 2
PUSH 0
EQ
MOD

这是不正确的。如何强制解析器的树先执行操作I%2,然后执行I%2==0?

您应该向bison声明
MOD
的优先级高于
EQ

%left EQ
%left MOD

必须在声明标记后执行此操作。

括号就是因为这个原因而存在的。因此优先级取决于标记的顺序或%left s的顺序??left s的顺序。您可以在左侧放置多个令牌。但这能解决你的问题吗?
%left EQ
%left MOD