help-bison
[Top][All Lists]
Advanced

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

Re: [REQUEST] Infinite recursion warning


From: Arthur Schwarz
Subject: Re: [REQUEST] Infinite recursion warning
Date: Sat, 14 Dec 2013 16:31:52 -0800 (PST)

exp:NIL
   | NIL list

list:NIL list

I won't address the issue of messaging (unqualified and this is an issue best 
addressed by the development team) but I will explore the grammar.

In LL (top-down, recursive descent) parser generators, the correct way to 
represent a list of items is:

list : token list
     { token
     ;

In LR (bottom-up) parser generators the correct way to represent a list is:

list : list token
     | token
     :

At run-time, using the wrong grammar may lead to an infinite loop terminated 
when there is no more memory. If the parser generator is 'generous' it will 
either convert the 'wrong' format into the 'right' format or will generate an 
error message. Your grammar can  not be easily disambiguated.


Bison is an LR parser generator. You're grammar is wrong for it.

Of more interest is your notion of putting a list in both the exp syntax 
equation and the list syntax equation. This is ambiguous (how do we interpret 
NIL NIL NIL?). So, with a little legerdemain we get:

exp : NIL
    : exp NIL
    ;

which should work.

Working on a class project?

art




reply via email to

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