[antlr-interest] python grammar(s)

Johannes Luber jaluber at gmx.de
Thu Apr 3 03:56:14 PDT 2008


alexander krohn schrieb:
> hi.
> 
> i'm trying to use the python grammars that exist. i found one for python 
> 2.3 done by terence and one updated version for python 2.5 done by frank.
> 
> both versions don't match with the grammar(s) i found on python.org
> 
> some example, the del-statement:
> 
> antlr-grammars just say:
> del_stmt : 'del' exprlist;
> 
> the grammar on python.org says something about
> 
> del_stmt ::=             "del" target_list
> 
> and for target_list:
> 
> target_list ::=             target ("," target)* [","]
>  
> target ::=             identifier
>                | "(" target_list ")"
>                | "[" target_list "]"
>                | attributeref
>                | subscription
>                | slicing
> 
> etc.
> 
> the "target"-stuff doesn't even exist in the antlr-grammars. they would 
> accept a line like
> del 1 + 1
> which python spits out with a SyntaxError.
> 
> there are some more things python does not accept, while the antlr 
> grammars do. how comes?
> 
> are these just meant as examples?

My theory is that the ANTLR python grammars are supersets over the 
specification on python.org. Such grammar definitions tend to include 
semantic limitations, which could be included in BNF form, but make it 
more difficult to create good error diagnostics from. The solution is 
then to do a second pass which filters the wrong semantics out.

Johannes


More information about the antlr-interest mailing list