tags:

views:

235

answers:

1

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 error, unexpected identifier:

+2  A: 

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.

Jonathan Leffler
Thanks very much Jonathan!
Nathan Campos