help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: signed numeric literals


From: Vukki Starborn
Subject: Re: signed numeric literals
Date: Thu, 18 Sep 2008 23:34:13 +0400

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 <address@hidden>

> 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
>
>
> _______________________________________________
> address@hidden http://lists.gnu.org/mailman/listinfo/help-bison
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]