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.)


List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/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
-~----------~----~----~----~------~----~------~--~---

Reply via email to