[antlr-interest] C# parser grammar problem

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


Gavin Lambert wrote:
> At 00:04 9/03/2007, Johannes Luber wrote:
>>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.
> 
> I'm not quite sure what you mean by this.  Lexer and parser rules act on
> different input as well (lexer rules act only on characters, and parser
> rules act only on tokens), so they're fairly different.  The
> capitalisation of the rule gives the hint to ANTLR about how to
> interpret the contents of the rule (eg. how it should treat
> string/character constants), so if you get it wrong then you'll usually
> (but not always) get an error, though it's not a particularly easy to
> understand one.  Especially since the capitalisation convention wasn't
> documented.

I meant, that ANTLR - or any other parser - could have as an
implementation a combined parser/lexer. It was supposed to be a
hypothetical supposition, which was supposed to show that the ANTLR
convention regarding parser and lexer rules isn't mere a "Best Practice"
to allow people to differentiate parser and lexer rules by their name
alone, but actively enforced. And because it is actively enforced, the
code analyzing the rules has a way to distinguish between both
varieties. And I heavily suspect that the key for this is the
referencing of other rules.

In any case, the actual point of my first email was that the behaviour
should be more explicitly documented, so first time users like me don't
have to struggle to get things right. Taking into account that at this
time not many successful tries for writing an own grammar could have
been done, it ends to be discouraging people from ANTLR use. I know this
personally from TYPO 3 - the gap between trivial templates and the
sophisticated ones is too big to cross for casual users and those go to
simpler CMS like Joomla.

Best regards,
Johannes Luber



More information about the antlr-interest mailing list