I’m trying to parse this syntax:
34 + 1 − 8, 32 * 87 + 6 / 4, 34 / 8
I’m expecting to ground it like this:
(, (- (+ 34 1) 8) (/ (+ (* 32 87) 6) 4) (/ 34 8))
This is the code for BISON:
%token NUMBER
%token COMMA
%token OPERATOR
%left OPERATOR
%left COMMA
%%
term: NUMBER | term op term ;
op: OPERATOR | COMMA;
%%
There is a problem:
test.y: conflicts: 2 shift/reduce
How can I solve it?
The problem is with your definition of
term:When parsing this, at each number, the question is: should I read another token to know if I have the first, or the second form.
A solution could be to define:
The grammar, once adapted, looks like the following:
compiles without warnings with
bison (GNU Bison) 2.4.1.