[antlr-interest] How can I set the text of a node?

Jim Idle jimi at temporal-wave.com
Tue Sep 22 10:24:26 PDT 2009


On 09/22/2009 09:06 AM, Pauba, Kevin L wrote:
> I have two rules for assignments to handle an optional LET keyword:
>
> ...
>      | KW_let				// Rule A
>        lhs = var
>        op = operator
>        rhs = expression
>        ->  ^(KW_let $lhs $op $rhs)
>      | lhs = var				// Rule B
>        op = operator
>        rhs = expression
>        ->  ^(KW_let $lhs $op $rhs)
>    

Your problem is here I think. try:

->^(KW_let["let"] .....


Jim
> ...
>
> Here's two related gunit test cases:
>
> "let $var = 15" ->  (let $var = 15)
> "$var = 15" ->  (let $var = 15)
>
> But when I run it, it fails on the second case:
>
> test10 (assignmentStatement, line22) -
> expected: (let $var = 15)
> actual: (KW_let $var = 15)
>
> Is there a way to set the text of the root node of the tree constructed with "Rule B" that would allow this test case to pass?
>
> I tried something similar to what's shown on pg. 183 of TDAR but I couldn't figure out how to add the child nodes for $lhs, $op and $rhs.
>
> Thanks!
>
>
> 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