[antlr-interest] how to skip/read next n Characters (n is read form input)

Thomas Ruschival thomas at ruschival.de
Sun Nov 18 13:54:33 PST 2012


Hi Jim,
thanks for the hint about anlr.markmail.org, I wasn't aware of this
userfriendly interface!
For sure I am working my way through terence's book and the mailing list.

> - When you are new to the game, I suggest that you do not use
> 'literals' in your parser grammars.
I started off with a textbook approach defining all token-rules for the
lexer and used only tokens in the parser rules. (btw. The initial
grammar worked well)
for instance I had defined:
BOLD : 'b'  'C';  // Lexer ruler  
However since the lexer is greedy it will always generate a BOLD token
for the sequence 'bC'. Which is per-se not a problem until I was
confronted with the rule to recognize n following bytes (original post).

> - val=. In a parser will capture every token, not any character, hence
it is not usually useful
I know, my workaround was to only have characters as tokens, so every
token had the length of 1 character, to not mess up the counter in the
readNchars rule.

Terence shared an antlr 4 grammar example (Data.g4) I will look into it
but since for the  initial real-world problem I am bound to antlr v3
(can't use java 1.6) it serves only for my academic interest. (and
future projects)

Best regards
Thomas


More information about the antlr-interest mailing list