[antlr-interest] python grammar(s)

Olivier Lefevre lefevrol at yahoo.com
Fri Apr 4 14:02:54 PDT 2008


Johannes Luber wrote:
> 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.

I also find that's can be a good idea to deliberately "widen" the syntax so 
as to "bless" errors that come up frequently (say, commas between array 
literal items when your language mandates spaces instead), letting them 
flow unimpeded through the parser, and then strike them down in a second 
pass on the AST. The reason is that it is easier to emit customized error 
messages in that second pass, where _you_ do all the checking, than it is 
to massage the rather obscure syntactic error messages you'd be getting 
from ANTLR otherwise.

-- O.L.



More information about the antlr-interest mailing list