lexing nested parenthesis

Carl Banks imbosol at vt.edu
Tue Jul 30 15:48:06 EDT 2002


Michael Hudson wrote:
> pinard at iro.umontreal.ca (Fran?ois Pinard) writes:
> 
>> [Kristian Ovaska]
>> 
>> > The language category you're dealing with is called context-free grammars.
>> > It's more expressive than regular languages, and it can parse any
>> > programming language.
>> 
>> Any? :-)
>>
>> I would not go that far.  There are strange beasts out there.
> 
> I was once told that this doesn't even cover Python: the meaning of
> "a=b" depends on whether you're in an argument list or not.

You were told wrongly.  I understand the confusion; the way a=b is
parsed does depend on its syntactic context, but a context-free
grammar refers to a grammar free of semantic context.

In other words, a non-context-free grammar will parse a=b differently
depending on the values of a and b (and other semantic state).

The reason no one says "semantic-context-free" is that a grammar free
of syntactic context is manifestly impossible, so there is no
ambiguity when saying "context-free."


-- 
CARL BANKS
http://www.aerojockey.com




More information about the Python-list mailing list