[antlr-interest] tree matcher: catch-all?
Tom Smith
yotommy at gmail.com
Wed Oct 13 05:57:43 PDT 2010
I have something that seems to work:
transition:
^(TRANSITION
( s1=stateName s2=stateName
arcBody { ... } // this is the valid subtree
| .* { FLAG_PROGRAMMING_ERROR_HERE() }
)
);
arcBody: {true}? ...
The wildcard matches when the subtree doesn't match arcBody, and the
(do-nothing) semantic predicate guarding the valid subtree suppresses
the ambiguity warning.
On Mon, Sep 27, 2010 at 11:17 AM, Tom Smith <yotommy at gmail.com> wrote:
> 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