[antlr-interest] Why waiting timeout? why cannot find symbol?

Gavin Lambert antlr at mirality.co.nz
Sat Nov 22 16:47:10 PST 2008


At 13:25 23/11/2008, Su Zhang wrote:
 >thank you for your reply, yet i still have some problems, why 
the
 >return rule timeTuple cannot be regarded as a string? just part 
of
 >my grammar below, and with error information
 >
 >validity  returns [String v]
 >    : ValidityHeader NotBefore tb= timeTuple NotAfter ta= 
timeTuple
 >      ValidityEnd { $v= $tb.getText() + $ta.getText(); }
 >    ;
 >timeTuple  returns [String time]
 >    : 'datime' '('t1= num ','t2= num ','t3= num ','t4= num ','
 >      t5= num ','t6= num ')' '.'
 >    {//time= new timeTuple(t1, t2, t3, t4, t5 ,t6);
 >     $time = "datime" + '(' + t1 + ','+ t2 +','+ t3 +',' + 
t4+','
 >       + t5+',' +t6 + ')';
 >    }
 >    ;
 >error information: unknown attribute for rule timeTuple: getText
[...]
 >even it won't work if I change   $v= $tb.getText() +
 >$ta.getText();
 >into $v=$tb+$ta;, it will show
 >
 >missing attribute access on rule scope: tb
 >missing attribute access on rule scope: ta

As I mentioned before, the correct syntax would be $tb.text, not 
$tb or $tb.getText().

$x.y is the ANTLR syntax for getting (or setting) the attribute y 
from label x.  Different target languages (and different versions 
of ANTLR, and in different contexts) resolve this into different 
bits of target language code, but the syntax in the grammar is 
uniform for convenience.

It's discussed in detail in the ANTLR book, and in passing (but 
sufficiently) in the Wiki.

(And remember to use Reply All to direct responses to the group as 
well.  You can get better results that way.)



More information about the antlr-interest mailing list