[antlr-interest] Regarding lexer rules return values
Dave Dutcher
dave at tridecap.com
Tue Jun 2 07:39:40 PDT 2009
Is there a reason you can't make LEXERRULE a parser rule?
parserrule: (parserrule2);
parserrule2: (LEXERRULE1) (LEXERRULE2) (LEXERRULE3);
Then you can do exactly what you want.
Dave
_____
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Raghavendra Anjana
(RBEI/EMT2)
Sent: Tuesday, June 02, 2009 4:27 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Regarding lexer rules return values
Hello,
I have a grammar with a parser rule as shown below
parserrule: (LEXERRULE);
LEXERRULE: (LEXERRULE1)(LEXERRULE2)(LEXERRULE3);
Whenever my parser rule is recognized I want to return the text identified
for LEXERRULE1,2,3 separately. But I believe that we cannot return values
from a lexer rule.
Is there a way so that I can get the LEXERRULE1,2,3 from LEXERRULE.
i.e. Something like
Parserrule return [x,y,z]: (LEXERRULE) {$x= LEXERRULE.LEXERRULE1;$y
=LEXERRULE.LEXERRULE2;$z=LEXERRULE.LEXERRULE3 };
LEXERRULE: (LEXERRULE1)(LEXERRULE2)(LEXERRULE3);
LEXERRULE1:'ab';
LEXERRULE2:'xy';
LEXERRULE3:'12';
The input for this parser is abxy12
The scenario is that whenver this text is recognized or matched then I want
ab, xy and 12 to be return back from the parser rule each separately.
Thanks a lot in advance.
Thanks and Regards
Raghavendra
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090602/b8413278/attachment.html
More information about the antlr-interest
mailing list