[antlr-interest] Interesting error in attribute access
bharath vissapragada
bharathvissapragada1990 at gmail.com
Sun May 6 08:48:28 PDT 2012
Hi all,
My grammar is as follows
A = blah blah (X|Y)? // I can have one or none X , Y but not both
Now my grammar is as follows :
A : blah blah (x=X|y=Y)?
-> {$x == null } ^(tok_blah X)
-> {$y == null} ^(tok_blah Y)
-> ^ (tok_blah)
;
When I compile my grammar .. It raises "missing attribute access on rule
scope" ..I googled a bit and changed my grammar to the following
A : blah blah (x=X|y=Y)?
-> {$x.text == null } ^(tok_blah X)
-> {$y.text == null} ^(tok_blah Y)
-> ^ (tok_blah)
;
and now the grammar compiles correctly. When I give the input as "blah
blah X" .. it parses it correctly ..However if I give
"blah blah Y" .. it fails ...I am using java and I looked into the source
of the code generated by grammar.
The code is trying to access attribute "text" of null variable $x without
checking if $x is null. Any workaround for this error?
I need to check it the variable $x is null instead of checking if its
'text" attribute is null. Any help is highly appreciated.
Thanks and Regards,
--
Regards,
Bharath .V
w:http://researchweb.iiit.ac.in/~bharath.v
More information about the antlr-interest
mailing list