[antlr-interest] C# parser grammar problem

Johannes Luber jaluber at gmx.de
Thu Mar 8 03:04:50 PST 2007

Gavin Lambert wrote:
> At 02:39 8/03/2007, Johannes Luber wrote:
>>Furthermore I've read through the relevant pages 85 and 86, but
>>there is no explicit sentence, which discriminates between lexer
>>and parser rules. After I repaired my grammar I realized that
>>the difference is simple. "If a rule doesn't include references
>>to other rules, it is a lexer rule, otherwise a parser rule."
>>It would have helped to lessen my learning curve.
> Actually no, that's not how it works :)  The difference is even simpler:
> lexer rules start with a capital letter and parser rules start with a
> lowercase letter.
> That one tripped me up for quite a while when I first started using
> ANTLR3, since I couldn't find anywhere on the website that mentioned the
> distinction.  (I haven't read the PDF, but it didn't exist at that point
> anyway.)

Your view isn't entirely right - while it is true, that ANTLR wants
lexer and parser rules distinguished through naming, naming isn't the
whole story. With my rule of thumb one knows when to use which naming
specification, and that isn't obvious even when having read the PDF, as
the BNF specifications I've come across never forced such a distinction.

Besides, if naming would be the only way to distinguish between parser
and lexer rules, how could ANTLR know when one uses the wrong naming
convention? I suppose that one could write a parser with doing the work
of the lexer so there would be no need to codify that convention in that
case. A simple "Best Practice" would be then sufficient.

Best regards,
Johannes Luber

More information about the antlr-interest mailing list