[antlr-interest] Contextual Tree Matching

David-Sarah Hopwood david-sarah at jacaranda.org
Thu Oct 22 22:16:25 PDT 2009


Joseph Cottam wrote:
> Solution #2:  Flag and filter
> @members{boolean inUpdate = false;}
> 
> topdown
>   : ^(UPDATE .*) {inUpdate = true;}
>   | {inUpdate}?=> RULE -> ^(RULE NEW STUFF);
> 
> bottomup: ^(UPDATE .*) {inUPdate = false;}
> 
> The use of state makes a serialization point to flag when I am in a in my
> otherwise nicely concurrent application, since there is now a global
> variable of the parser called inUpdate.

Well, you won't be able to use an ANTLR lexer/parser object concurrently in
more than one thread, since they are heavily stateful in any case. The
problem with the pattern above is that it isn't reentrant, if an UPDATE can
contain a QUERY or vice versa. I don't know whether that is the case for
your language; if it is, then look at using dynamically scoped attributes.

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com



More information about the antlr-interest mailing list