[antlr-interest] Attribute in Tree grammar. Semantic predicates with Alternative clause Problem

Johannes Luber jaluber at gmx.de
Thu Oct 30 16:08:10 PDT 2008


Петров Александр schrieb:
> Hello,
> 
> I'm using semantic predicates in tree grammar:
> 
> //deviceID is a rule
> deviceFuncID
> :     ^(NODE1 ^(NODE2 ^(NODE3 deviceID)))
>         (
> 	{
>                    //IsID function has signature:  bool IsID(string id)
>                     IsID(
> 	           $deviceID.text,
>                           )
>                   }?
> 	-> oneTemplate(...)
>                 |-> otherTemplate(...)
>          );
> 
> deviceID	:	'this'->{%{"this"}}
> 
> But when I try to compile generated C# code (antlr 3.1.1)I have many
> errors like that:
> 
> ---- The name 'deviceID25' does not exist in the current context
> 
> In antlr 3.0.1 such grammar produce compilable code.
> If I rewrite that code as (remove brackets)
> 
> deviceFuncID
> :     ^(CCALL ^(CSYNCCALL ^(OBJECTNAME deviceID)))
> 
> 	{
>                     IsID(
> 	           $deviceID.text,
>                           )
>                   }?
> 	-> oneTemplate(...)
>                // |-> otherTemplate(...)
> 
> Then all right, but I want to have alternative clause for semantic predicate.
> If I uncomment alternative clause, then I have:
> 
> ---- error(201):  The following alternatives can never be matched: 2
> 
> What should I do ? What is the cause of such errors ?
> 
> Thank you

Without the full tree grammar I can't check for the source of the
problems. Can you send it to me along with the combined grammar (or at
least the tokens file of the combined grammar)?

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



More information about the antlr-interest mailing list