[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Precedence and "overloaded" operators
From: |
Víctor M. González |
Subject: |
Precedence and "overloaded" operators |
Date: |
Sat, 02 Jan 2010 19:22:53 -0300 |
User-agent: |
Thunderbird 2.0.0.23 (Windows/20090812) |
Hi.
Given the following operators:
%left '+' '-'
/*...*/
%right SOME_UNARY_OPERATOR
%left STRING_CONCATENATION
And the following rules:
integer:
SOME_UNARY_OPERATOR string ;
string:
STRING |
string '+' string %prec STRING_CONCATENATION ;
Bison can't figure out the correct precedence for "string '+' string",
and no matter what I do, the report insists that ('+' <
STRING_CONCATENATION), which is a problem because it understands the
string (SOME_UNARY_OPERATOR "str"+"ing") as ((SOME_UNARY_OPERATOR
"str")+"ing"), which is a syntax error.
However, if I leave out the first '+' (the one just above the /*...*/),
it finally works as it should.
I can also get around it if I change the troublesome rule to
STRING '+' string %prec STRING_CONCATENATION
That forces Bison to delay the reduction of the rule, but at the cost of
stack space.
Is this a bug or am I doing something wrong?
- Precedence and "overloaded" operators,
Víctor M. González <=