[antlr-interest] Lexical hacks ... again.

Jim Idle jimi at temporal-wave.com
Sun Feb 27 12:45:08 PST 2011


Yes you can do this, but it is a little hacky. First you will need to
create a token vocab file:
X=4
Y=5

etc and import it in to both lexers. Then you will need to embed some java
code to hand off the input stream to your second lexer and have it add
tokens to the current token stream. You should be able to do that.

However, before doing that, take a look at the island grammar examples.
This may be more elegant for your needs if the switch over can be
lexically detected. Look to that first.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of g4 at novadsp.com
> Sent: Sunday, February 27, 2011 6:41 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Lexical hacks ... again.
>
> Right. ANTLR != PCCTS. Wow.
>
> I've written a modest utility to transform CoCo/R grammar specs to
> ANTLR 3. CoCo/R allows syntactic predicates (for LL(1) disambiguation)
> to be embedded as 'IF' '(' anything ')'. Not wanting to parse all the
> code I've dealt with this by having the lexer eat all content after
> spotting the 'IF'.
>
> Question is this: Is there any way to embed a 'sub-lexer' at this
> point?
> i.e. grab the input stream and point it at a lexer for C#/C code?
>
> I don't need to evaluate the expression itself but storing lexical
> tokens rather than characters would be a plus in later stages of
> analysis.
>
> Thx++
>
> Jerry.
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list