help-bison
[Top][All Lists]
Advanced

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

Re: Operator precedence with empty operator


From: Hans Aberg
Subject: Re: Operator precedence with empty operator
Date: Tue, 23 Mar 2010 20:57:20 +0100

On 23 Mar 2010, at 20:32, Пётр Прохоренков wrote:

I'm trying to write a grammar file for parsing expressions. The main part
goes as following:

%left '-' '+';
expr: expr '+' expr
   | expr '-' expr
// Other operators...
   | expr expr
   | const
   | id
   ;

"expr expr" here is function application, former expr is the function and
latter expression is an argument (as in Haskell).

You check the .y file of Hugs <http://haskell.org/hugs/>.

I don't understand what is wrong with %prec as documentation says it assigns
precedence to rule.

If you look into the .output file for the parsing position "." in the state of the conflicting rules, then it uses the precedences of the two token immediately before and after that dot (one token from each). If there are not two such tokens available, because they way the rules have been written, the method fails.

  Hans



reply via email to

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