[antlr-interest] tree matcher: catch-all?

Tom Smith yotommy at gmail.com
Mon Sep 27 08:17:34 PDT 2010


I am using a tree matcher to operate on specific subtrees.  However,
sometimes when I make changes to the tree-generation phase, I fail to
make the required matching changes in my tree matcher.  The result is
that the subtree doesn't match, which does not bother the tree matcher
in the least.  Instead, I'd like to flag this situation, so that I
realize I have a programming error.

In particular, my Trans.g looks like:

tree grammar Trans;

options {
	tokenVocab=SsipAST;
	output=AST;
	ASTLabelType=CTree;
	filter = true;
}

topdown: transition;

transition:    ^(TRANSITION s1=stateName s2=stateName arcBody[$s1.text]
               {  // Do some management here
               };

Every subtree that starts with TRANSITION should match this rule, but
in the development process, sometimes they don't.  Any suggestions how
to catch these situations?

I tried something like:

transition:    ^(TRANSITION ( s1=stateName s2=stateName
arcBody[$s1.text] { ... } | .* { FLAG_ERROR_HERE() } );

... but this of course leads to ambiguity warnings:

Decision can match input such as "PREDICATE DOWN Identifier DOWN..UP"
using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input

Ideas?

Thanks,
Tom Smith.


More information about the antlr-interest mailing list