[antlr-interest] A simple question for v2.7.7

YiQing Yang yiqing at objectivity.com
Thu Jun 21 13:08:04 PDT 2007


Hi,

 

Sorry that I am still asking questions for V2 while everyone else seems
using V3 right now. I wish I could use V3 too, but C++ target is not
supported yet.

 

My question is very simple. Is label to a rule reference allowed in V2? 

 

For example, in the following parser rule, I can put a label for the token
reference NAME and use it in the action to print the text of the token. 

 

operator_symbl_name

  : operator_symbol

  | n:NAME {if (n!=0) cout << "Operator Name: " << n.get()->getText() <<
endl;;}

  ;

 

I would like to do the same thing for the rule reference "operator_symbol".
I tried the following:

 

operator_symbl_name

  : s:operator_symbol {cout << "Operator Symbol: " s.get()->getText() <<
endl;}

  | n:NAME {cout << "Operator Name: " << n.get()->getText() << endl;}

  ;

 

The parser generation does not give me any error. But when compiling the
parser, it gives me the error 

 

error C2065: 's' : undeclared identifier

 

I know my way to use "s" in the action code is wrong since it is not a token
reference. But the error showed that it is not even declared.

 

The ANTLR Reference Manual says that "Any atomic or rule reference
production element can be labeled with an identifier." But how to use a
lable for a rule reference?

 

I would appreciate if anyone could give me an answer. 

 

Last time when I asked when the C++ will be supported in V3, I got the
answer that it will be around June. Any updates for the V3 C++ delivery time
frame?

 

Thanks a lot,

 

Yiqing

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070621/2606a2f2/attachment.html 


More information about the antlr-interest mailing list