lexing nested parenthesis

Kristian Ovaska kristian.ovaska at helsinki.fi
Wed Jul 31 05:05:31 EDT 2002


pinard at iro.umontreal.ca (François Pinard):
[context-free grammars]
>> it can parse any programming language.
>I would not go that far.  There are strange beasts out there.  Moreover,
>people usually throw good parts of the complexity in "semantic analysis"
>passes.

You're right, of course. The point was that context-free grammars are
fundamental building blocks of parsers and you have to learn them if
you want to write real parsers.

Perl must be hard to parse, just think about that regexp stuff for
instance!

>In the caricatural case, your grammar may parse individual
>characters and leave it all to later compilation stages, so a fortiori, any
>kind of parser will do.  We are diving in the complex art of compromises! :-)

And a real world case is the handling of reserved keywords. Perhaps
this is on the scanner side, but it illustrates the principle: often
all names are recognized with a single rule, and then the token is
checked for whether it's a keyword or a normal name.

>PLEX and PLY are not so compact, they also require some more work to use,
>but they reward us with speedier analysis, especially for bigger grammars.

PLY has good error reporting, too.

-- 
Kristian Ovaska <kristian.ovaska at helsinki.fi>



More information about the Python-list mailing list