grammar question

Courageous jkraska at san.rr.com
Wed Feb 27 00:03:30 EST 2002


>For these reasons, saying just "Python's grammar is
>LL(1)" is oversimplifying things considerably.

I can't speak to Python's parser and its generator,
but as for someone who is currently building and maintaining
an ANTLR (http://www.antlr.org) LL(k) grammar for a Python
derivative, I can say that it's quite definitely possible
to do, and without writing a whit of custom parser code.

I will point out that ANTLR has a feature called "syntactic
predicates" which allow you in effect to selectively make
extend the k by some fixed amount n, where specific terms
in a specific order disambiguate the grammar. Whether you
regard this as strict LL(k) is up to you, but as ANTLR is
one of the top LL(k) opensourced parser generators on the
market, the question is at best academic.

Indentation sensitivity can quite simply and very cleanly
be achieved by using ANTLR lexer multiplexing. This can
be expressed very, very succinctly in an ANLTR grammar,
where you tell it that [] {} and () use indent
insensitive mode for all inner terms, but is by default
otherwise indent-sensitive.

C//




More information about the Python-list mailing list