[antlr-interest] Island grammar in AntlrV3

David Holroyd dave at badgers-in-foil.co.uk
Sat Sep 2 16:01:43 PDT 2006


On Sat, Sep 02, 2006 at 11:09:32PM +0400, Ilia Kantor wrote:
> I have island grammar, that becomes known on parsing stage.
> 
> How can I parse it with separate lexer/parser, 
>   adding result to common tree ?

I've also been wondering about this, but I don't have an answer yet.

I'm worried that by the time the parser has the chance to try and fiddle
with the lexer, lookahead has consumed the input anyway.  Maybe the
standard infrastructure can let the input character stream 'backtrack'?

My specific use case is regular expression literals, e.g. I'd like to be
able to handle,

  r =   / b; f = r/m;  // regexp literal with 'm' flag
  r = a / b; f = r/m;  // two expr-statements involving division

It seems that the lexer needs context from the grammar in order to tell
what to do on seeing '/'.

I've seen that the ECMAscript grammar on antlr.org sidesteps this
difficulty by dispensing with a lexer per se, and doing everything in the
parser.  This makes my brain itch.  :)


Any clues?
ta,
dave

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list