我有以下Bison语法:
%%
input:
expression { cout << $1 << endl;}
;
expression:
INT
| OP PLUS expression expression CP {$$ = $3 + $4;}
| OP MINUS expression expression CP {$$ = $3 - $4;}
| OP MULT expression expression CP {$$ = $3 * $4;}
| OP DIV expression expression CP {$$ = $3 / $4;}
| OP PLUS expression expression exprseries CP {$$ = $3 + $4 + $5;}
;
exprseries:
expression
| expression exprseries {$$ = $1 + $2;}
;
%%
OP
和CP
分别是开括号和近括号。
我希望它识别(+ <exp1> <exp2> ... <expn>)
并计算总和。不幸的是,它只识别(+ INT INT ... INT)
和(+ INT <exp1> <exp2> <exp3>)