[antlr-interest] Island Parsing - a different way, seems to work

Mark Mandel mark.mandel at gmail.com
Mon Jun 18 03:52:15 PDT 2007


Aha.

I see that now.

This seems to kinda follow the same sort of lines as the example (sorta-ish)

I was just surprised that it worked, more than anything else.

Thanks for the heads up on the example, that gives me some extra ideas
as well for some of the stuff I am doing.

Cheers,

Mark

On 6/18/07, David Holroyd <dave at badgers-in-foil.co.uk> wrote:
> On Mon, Jun 18, 2007 at 05:23:18PM +1000, Mark Mandel wrote:
> > Hey all,
> >
> > I've been playing around with Island Parsing, and I think I've come up
> > with a much simpler way of doing it other than the one that is in the
> > wiki
> > (http://www.antlr.org/wiki/display/ANTLR3/Island+Grammars+Under+Parser+Control)
>
> Hey!  My page :)
>
>
> > The code ended up looking pretty much like this:
> >
> > startTag
> >       :
> >       (
> >       sto=START_TAG_OPEN stc=START_TAG_CLOSE  tc=tagContent
> >               (
> >               -> ^(CFTAG[$sto] START_TAG_CLOSE
> >                                               {
> >                                                       parseScript(stc, tc)
> >                                               }
> >                                                 tagContent)
> >               )
> >       )
> >       ;
>
> To be honest, I suspect you are trying to solve a simpler problem than
> the kind which the 'under parser control' approach is tackling.  i.e.
> your lexer is able to unambiguously recognise START_TAG_OPEN without any
> additional context.  You should absolutely use a simpler approach than
> the one on that wiki page if you possibly can!  :)
>
> In some languages (e.g. the regex island grammar example from the wiki
> page) it is not possible for the lexer to work out what's going on
> without knowledge of what came before.  Getting the parser to talk to
> the lexer so that the parser can supply this context needs a whole lot
> of additional wiring that ANTLR doesn't deliver by default at the
> moment.  That's why the example code is so complicated.
>
> Have a look at 'island-grammar' from the examples-v3 download for
> another approach handling a language that's closer to yours (I think).
>
>
> Hope that makes sense!
> dave
>
> --
> http://david.holroyd.me.uk/
>


-- 
E: mark.mandel at gmail.com
W: www.compoundtheory.com


More information about the antlr-interest mailing list