[antlr-interest] HELP requested again with StringTemplate and java backslash characters.

Ramanand Mandayam ramanand_mandayam at yahoo.com
Wed Aug 20 17:21:48 PDT 2008


Hello there, 

Sorry to broadcast my request again but I am somewhat at a loss.

I have a tree grammar that parses expressions which include just "string types". 
In the grammar options I have specified output=template.
When I print out the text associated with a (string) token I get the correct output.
But the output is not correct when the input sentence contains a binary operation or involves traversing a non-leaf node in the tree.
 
For example, assume that the input is A+B where both A and B are string types. 
My tree grammar collects the output of A and B and they both seem to be correct at the leaf (TOKEN) nodes in the tree traversal.
At the next step higher, the grammar collects the two and adds the "+" string in between the two strings from the two leaf nodes.
 
However, the string template assignment to "retval.st" (which is the return value of the non-terminal representing the '+' operation)
compresses two successive '\' '\' characters into a single '\', as a result of which the output has a completely different meaning.
 
As an example, if the token text is "A:\\B", then the output of the tree grammar magically becommes "A:\B".
This seems to happen only at internal tree nodes that pass the retval.st value by using the JAVA assignment operator.
 
Anybody have any clue what is happening here? Any options that need to be set in the call to the output operator?
Can somebody help me work around this issue.
 
Cheers
 
Ramanand


      


More information about the antlr-interest mailing list