[antlr-interest] anybody help with me a python grammar rule?

Terence Parr parrt at cs.usfca.edu
Tue Feb 24 16:15:23 PST 2004


On Feb 22, 2004, at 6:16 AM, John Pybus wrote:
>>> Can anybody give me some examples of the various things parameters
>>> might look like in the wacky cases?
>
> def foo(x,y,z):  #GOOD
>
> def foo(x,y,z,): #GOOD trailing comma allowed
>
> def bar(*baz):   # STILL GOOD
>
> def bar(*baz,):  # BAD Syntax error !!
>
> i.e. You're allowed a trailing comma in a parameter list, unless you're
> using either of the excess positional parameter forms.  Though I won't
> to pretend to answer why this should be the rule ;-)

Hi John,

Ok, thanks...

> Terence Parr wrote:
>> For example, won't this rule generate the same language?
>>
>> parameter_list:
>>      defparameter (',' defparameter)*
>>      ( ','
>>        ('*' NAME [',' '**' NAME]       | '**' NAME
>>        )
>>      )
>>   | '*' NAME [',' '**' NAME]
>>   | '**' NAME
>>
>> and it's LL(1).
>>
>> arglist has the same problem.  I wonder what kinda parser they build
>> from this grammar.  Ick.
>>
>> Ter
>
> How does this match a param_list not ending in one of the 'excess
> parameter' forms?
>
> foo(a) or foo(a,)
>
> I think you'll need the form they've used (or something similarly
> complex) to get the optional trailing comma on simple parameters, but
> not on *'d ones.

Ooops...yeah, I guess that should be optional...rats.  Thought I'd 
figured that one out.

Python is seeming very cool in it's power and expressivity, but pretty 
odd in its quirks ;)

Ter
--
Professor Comp. Sci., University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
Cofounder, http://www.knowspam.net enjoy email again!
Cofounder, http://www.peerscope.com pure link sharing





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list