On 04/30/2011 11:34 AM, Courtney Falk wrote:
>   I'm not certain this is a feasible strategy.  Please let me know if 
> I'm working on something that's not possible.
> 
> I have a grammar, Alpha, that generates an AST as the first processing 
> stage.  What I'm trying to do is use a tree grammar, Beta, that looks at 
> the AST nodes and attempts to match them against a second, different 
> lexical pattern.
> 
> The grammars might look like:
> 
> //-----
> 
> grammar Alpha
> 
> options { ASTLabelType=CommonTree; output=AST; }
> 
> tokens { ROOT; MATCH; DONTMATCH; }
> 
> root : subnodes+ -> ^(ROOT subnodes+);
> 
> subnodes : numbers | characters;
> 
> numbers : NUMBERS -> ^(DONTMATCH NUMBERS);
> 
> characters : CHARACTERS -> ^(MATCH CHARACTERS);
> 
> WHITESPACE : (' ' | '\r' | '\n' | '\t')+ { $channel = HIDDEN; }
> 
> NUMBERS : ('0'..'9')+;
> 
> CHARACTERS : ('a'..'z')+;
> 
> //-----
> 
> tree grammar Beta;
> 
> options { filter=true; tokenVocab=Alpha; }
> 
> root : ^(ROOT subnodes+);
> 
> subnode : numbers | characters;
> 
> numbers : ^(DONTMATCH NUMBERS) { System.out.println("Don't match"); };
> 
> characters : ^(MATCH rematch);
> 
> rematch : 'aaa' { System.out.println("Triple A"); }
> 
> //-----
> 
> I can't seem to find of way of making the "rematch" rule work.

You grammar doesn't have an 'aaa' token.  It does have CHARACTERS
tokens.  If 'aaa' is special, then you need to match it in your grammar
like a keyword.  Then you can reference it in your tree grammar.
Otherwise you will need to match any CHARACTERS token in your rematch
rule and do what you need to when the value is 'aaa' and do something
else when it is not.

Your tree grammars can only work with the tokens your lexers produce
(and the same set that your parsers use as well).

> Courtney Falk
> [email protected]

-- 
Kevin J. Cummings
[email protected]
[email protected]
[email protected]
Registered Linux User #1232 (http://counter.li.org)

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to