help-bison
[Top][All Lists]
Advanced

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

Operator precedence with empty operator


From: Пётр Прохоренков
Subject: Operator precedence with empty operator
Date: Tue, 23 Mar 2010 22:32:40 +0300

Hi,

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).
What I need is function application having maximum priority and left
associativity. For some reason default behavior is the exact opposite:
minimum priority and right associativity.
So the first thing I've tried was declaring "%left APPLY;" and then adding
"%prec APPLY" to the corresponding line.
However, that changed nothing.
I was able to sort the problem with priority out by introducing new
non-terminal (just like priorities are handled in recursive parsers), but
associativity is still a problem here.

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

So can I be missing something fundamental about operator precedence in
bison?
Any other pointers how to get the desired behavior?

-- Regards, Petr.


reply via email to

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