Ply(LALR) and Yacc behaving differently
Carsten Haese
carsten at uniqsys.com
Fri Apr 8 13:30:16 EDT 2005
On Thu, 2005-04-07 at 14:51, Åsmund Grammeltvedt wrote:
> Hi.
>
> I am trying to implement a small compiler in python and, trying to use
> something a bit more pythonic than lex/yacc, ended up with ply
> (http://systems.cs.uchicago.edu/ply/). The only problem is that whereas
> yacc accepts the grammar and appears to parse it correctly, ply does not.
>
> Perhaps this belongs on some compiler list, but I couldn't decide if it
> was a compiler or a python problem, so bear with me.
Maybe this is a PLY bug? LALR(1) support appears to be a relatively
recent addition to PLY. Have you tried contacting PLY's author?
For what it's worth, it appears that you can make your example grammar
work in LALR-mode PLY by eliminating the empty production and making the
Block rule right recursive like this:
def p_Goal(p):
"""
Goal : Block
"""
def p_Block(p):
"""
Block : SEMI
| T Block
| S Block
"""
Of course, I don't know whether this rewrite is applicable to your
larger grammar.
Hope this helps,
--
Carsten Haese - Software Engineer | Phone: (419) 861-3331
Unique Systems, Inc. | FAX: (419) 861-3340
1446 Reynolds Rd, Suite 313 |
Maumee, OH 43537 | mailto:carsten at uniqsys.com
More information about the Python-list
mailing list