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)
The problem is with your definition of term
:
term: NUMBER | term op 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:
term: NUMBER reminder;
reminder: /* empty */ | op term;
The grammar, once adapted, looks like the following:
%token NUMBER
%token COMMA
%token OPERATOR
%left OPERATOR
%left COMMA
%%
term: NUMBER reminder;
reminder: /* empty */ | op term;
op: OPERATOR | COMMA;
%%
compiles without warnings with bison (GNU Bison) 2.4.1
.