On 08/23/2013 02:53 PM, Stefan J wrote:
> Hi,
>
> I am currently redesign my old compiler written in python by the use of pyl. The current code is
> attached.
> start :
> | startElement
> | start startElement
>
> startElement : comment
> startElement : global { varList }
>
> varList :
> | varListElement
> | varList varListElement
>
> varListElement : comment
> varListElement : type name ;
> varListElement: type name [ number ] ;
>
> As you can see it is very simple. I did not understand the error (4 Shift / Reduce Erros). Maybe you
> can help me.
I threw the thing in bison, and it gave me the grammar below, and also 4 shift/reduce errors.
Grammar
0 $accept: start $end
1 start: /* empty */
2 | startElement
3 | start startElement
4 startElement: COMMENT
5 | GLOBAL CUROPEN varList CURCLOSE
6 varList: /* empty */
7 | varListElement
8 | varList varListElement
9 varListElement: COMMENT
10 | TYPE NAME
11 | TYPE NAME SQOPEN NUMBER SQCLOSE
It also tells where they are:
State 0 conflicts: 2 shift/reduce
State 5 conflicts: 2 shift/reduce
The problem is in the start productions and the varList productions.
As you can see there are 3 production rules, one for 0 elements, one for 1 element, and the general
case.
The problem is caused by the fact that you have two ways to derive 1 element, namely as 1 element,
or as 0 elements and 1 application of the general case.
I think you want to remove the 1 element production rules.
Albert