Section 5.4 (Context dependent precedence) in the official manual (
http://www.gnu.org/software/bison/manual/html_mono/bison.html#Contextual-Precedence)
contains the answer:

Here is how %prec solves the problem of unary minus. First, declare a
precedence for a fictitious terminal symbol named UMINUS. There are no
tokens of this type, but the symbol serves to stand for its precedence:

     ...
     %left '+' '-'
     %left '*'
     %left UMINUS

Now the precedence of UMINUS can be used in specific rules:

     exp:    ...
             | exp '-' exp
             ...
             | '-' exp %prec UMINUS



2008/9/18 Jack Andrews <[EMAIL PROTECTED]>

> hi guys,
>
> in the context of a C like language, how do i parse/lex a signed
> literal? eg: "-1".  (speech marks excluded)
>
> in the lexer, i can't tell if we're in an expression  eg:  "2-1"  or
> if we're in assigment: "int x=-1".  i've studied the freely available
> C grammar for hints, but can't find an answer.  in know of at least
> one language that avoids this problem by using '_' instead of '-'.
>
>
> ta, jack
>
>
> _______________________________________________
> help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison
>
_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to