Bison Syntax Error (Beginner)
I'm back and now writing my own language and my OS, but as I'm now starting in the development of my own development language, I'm getting some errors when using Bison and I don't know how to solve them. This is my *.y file code:
input:
| input line
;
line: '\n'
| exp '\n' { printf ("\t%.10g\n", $1); }
;
exp: NUM { $$ = $1; }
| exp exp '+' { $$ = $1 + $2; }
| exp exp '-' { $$ = $1 - $2; }
| exp exp '*' { $$ = $1 * $2; }
| exp exp '/' { $$ = $1 / $2; }
/* Exponentiation */
| exp exp '^' { $$ = pow ($1, $2); }
/* Unary minus */
| exp 'n' { $$ = -$1; }
;
%%
And when I try to use Bison with this source code I'm getting this error:
calc.y:1.1-5: syntax e开发者_运维百科rror, unexpected identifier:
You need a '%%' before the rules as well as after them (or, strictly, instead; if there is no code after the second '%%', you can omit that line).
You will also need a '%token NUM' before the first '%%'; the grammar then passes Bison.
Another alternative solution exists, which is to upgrade to bison
version 3.0.4
. I guess between version 2.x
and 3.x
, they changed the file syntax.
精彩评论