I am making a simple compiler for expressions, however I am stuck figuring out how to use Bison's precedence keywords
In my lexer I define the following check:
'-' {ECHO;return(MINUS);}
However, I noticed that when evaluating expressions, '-' can have two meanings, 1) for subtraction and 2) for negation of an number, and both have different precedences.
In my parser file how would I account for this by using %left and %right to define associativity?
I know I can do
%left PLUS
%left MINUS
... and so on
For each such token, but since negation has right associativity and higher precedence, how would I include that in here, since I do not think I can do
%left PLUS
%left MINUS
%right MINUS /* This is the negation one */
Thanks for your help!