Recursion in Python grammar

G. David Kuhlman dkuhlman at netcom.com
Thu May 27 13:41:18 EDT 1999


Have you looked at Python-1.5.2/Grammar/Grammar in the Python
source distribution?

I made a quick scan and did not see left recursion there, although
I'm not sure I would recognize a left recusive grammar rule if I
saw one in full sun-light.

Also, look at Python-1.5.2/Parser/*.  I don't know what your
purposes are, but that parser generator might do what you want.
It's an interesting read, whatever you goals.

By the way, anyone who would explain the differences between
antlr's approach to generating parsers (antlr generates recursive
descent parsers with look-ahead) and the Python parser approach (it
generates an nfa (non-deterministic finite autonoma) for each
grammar rule, right?) would gain my thanks.

  - Dave


Magnus L. Hetland <mlh at idt.ntnu.no> wrote:

> Hi!

> I'm trying to make a grammar file for ANTLR (www.antlr.org) with the
> Python grammar (Has anyone done this?) I'm trying to use the rules
> from the language ref directly, but I am having problem with all the
> left-recursion that is everywhere... Is there a more "well-behaved"
> version of the grammar somewhere, or am I just missing something
> obvious? (It seems that making a parser with all that left-recursion
> is a bit problematic... At least ANTLR won't accept it.)

> --

>   Magnus
>   Lie
>   Hetland        http://arcadia.laiv.org <arcadia at laiv.org>




More information about the Python-list mailing list