[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: shift/reduce conflict with unary
From: |
Derek M Jones |
Subject: |
Re: shift/reduce conflict with unary |
Date: |
Tue, 21 Aug 2007 10:36:51 +0100 |
User-agent: |
Thunderbird 2.0.0.0 (Windows/20070326) |
cwcaceres wrote:
Hi, I'm having shift/reduce conflict with the unary expression in my grammar
file. I've tried using the %prec modifier but it doesn't seem to work.
It does work, but just not in the way you wanted it to (because you have
put it in the wrong place, but then I would probably not used it).
I take it the shift reduce conflict occurs on the input:
NUMBER PLUS NUMBER potentially-other-tokens
which can be reduced to a single summation expression
or shifted because there may be a following UPLUS
Your problem is that you are trying to do too much in too few rules.
Create some productions for the unary operators and separate ones for
the binary operators. See how the C standard has done it, for an
example.
%token NUMBER
%token BIT_NOT NOT
%left PLUS MINUS OR XOR
%left UPLUS
%%
expression_list
: /* empty */
| expression_list summation_expression
;
summation_expression
:unary_expression
| summation_expression PLUS unary_expression
| summation_expression MINUS unary_expression
| summation_expression OR unary_expression
| summation_expression XOR unary_expression
;
unary_expression
: NUMBER
| PLUS NUMBER %prec UPLUS
| BIT_NOT NUMBER
| NOT NUMBER
;
I hope someone can help me with this. Thanks.
--
Derek M. Jones tel: +44 (0) 1252 520 667
Knowledge Software Ltd mailto:address@hidden
Applications Standards Conformance Testing http://www.knosof.co.uk
- shift/reduce conflict with unary, cwcaceres, 2007/08/21
- Re: shift/reduce conflict with unary,
Derek M Jones <=
- Re: shift/reduce conflict with unary, cwcaceres, 2007/08/21
- Re: shift/reduce conflict with unary, Derek M Jones, 2007/08/21
- Re: shift/reduce conflict with unary, cwcaceres, 2007/08/22
- Top Dowm Variable Communication, Arijit Das, 2007/08/22
- Message not available
- Re: Top Dowm Variable Communication, Ramón García, 2007/08/22
- Re: Top Dowm Variable Communication, Evan Lavelle, 2007/08/22
- Re: Top Dowm Variable Communication, Evan Lavelle, 2007/08/22
- Message not available
- Re: Top Dowm Variable Communication, lfinsto1, 2007/08/22
- Re: Top Dowm Variable Communication, Ramón García, 2007/08/24
- Re: shift/reduce conflict with unary, Evan Lavelle, 2007/08/22