Imaginary node modifies tree unexpectedly.
Bug, Grrr, or not what I expected?
In the following grammar, rule a invokes rule b twice sequentially.
The first b is captured as b1, and the second b is captured as b2.
If rule b does not create an imaginary token, then both the trees for b1 and
b2 are created as expected.
However, if rule b creates an imaginary token, then tree b1 is created as
expected at first.
When b2 is created, b1 is changed and now holds the value of both b1 and b2,
when only b1 is expected.
====
grammar InvalidTreeBuild001;
options
{
language = 'CSharp2';
output = AST;
}
// Imaginary Tokens
tokens
{
I1;
I2;
}
a : b1=b b2=b
;
// No imaginary created
//b
// : IntegerDigit -> ^(I1 IntegerDigit)
// ;
// Imaginary created
b
: IntegerDigit -> ^(I1 IntegerDigit) ^(I2 IntegerDigit["0"])
;
WS : (' ' | '\r' | '\t' | '\u000C' | '\n') {$channel=HIDDEN;}
;
IntegerDigit
: ('0'..'9')
;
=====
Input
1 2
-----
For No imaginary created
Before b2=b
b1 = (I1 1)
b2 = nil
After b2=b
b1 = (I1 1)
b2 = (I1 2)
-----
For Imaginary created
Before b2=b
b1 1 = (I1 1) (I2 0)
b2 = nil
After b2=b
b1 = (I1 1) (I2 0) (I1 2) (I2 0) <- Why did (I1 2) (I2 0) get added to b1?
b2 = (I1 2) (I2 0)
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.