[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
problems with absolute value structure in algebraic grammar
From: |
Samad Lotia |
Subject: |
problems with absolute value structure in algebraic grammar |
Date: |
Sat, 21 Jun 2003 11:25:09 -0700 (PDT) |
Here is my grammar from y.output:
0 $accept : statement_list $end
1 $$1 :
2 statement_list : statement_list statement $$1
terminal
3 |
4 | statement_list error terminal
5 | terminal
6 terminal : TERMINAL
7 | EOL_TERMINAL
8 statement : enclosed_statements
9 | statement '+' statement
10 | statement '-' statement
11 | statement '*' statement
12 | statement '/' statement
13 | statement '%' statement
14 | '-' statement
15 | SYMBOL '=' statement
16 enclosed_statements : enclosed_statement
17 | enclosed_statements
enclosed_statement
18 enclosed_statement : VALUE
19 | SYMBOL
20 | enclosed_statement '^'
enclosed_statement
21 | '(' statement ')'
22 | '|' statement '|'
23 | FUNC_NAME '(' param_list
')'
24 param_list :
25 | polyparams
26 polyparams : statement
27 | polyparams ',' statement
The purpose of this grammar file is to produce a
parser which can parse algebraic expressions. The
purpose of the enclosed_statements rule is to support
implicit multiplication. For example, the expression:
9acos(0.5)
Really means:
9*acos(0.5)
Or the expression:
8|-2|(2^3)
Really means:
8*abs(-2)*(2^3)
When bison parses this grammar file, it reports a
shift/reduce conflict at line 22. It, for some reason,
cannot accept rules like this:
enclosed_statement: (a_token) statement (same_token)
For example, if I change line 21 from
enclosed_statement :
21 | '(' statement ')'
To:
enclosed_statement :
21 | '(' statement '('
This also produces a shift/reduce conflict. However,
if I change the left-hand side from
"enclosed_statement" to "statement," there is no
shift/reduce conflict. For example:
statement: '|' statement '|'
Is accepted and works but:
enclosed_statement: '|' statement '|'
does not work.
How can I solve this shift/reduce conflict?
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
- problems with absolute value structure in algebraic grammar,
Samad Lotia <=