[antlr-interest] Extracting match
Alexey Demakov
demakov at ispras.ru
Tue Mar 7 00:40:02 PST 2006
Hi Andrew,
Rules can return values:
rule1 returns [String text=null]
:
{ text = LT(1).getText(); }
( "foo" | "bar" | "baz" )
;
rule2
{
String text1 = null;
String text2 = null;
}
: x
text1=rule1 { if( text1.equals( "foo" ) ) System.out.println( "FOO" ); }
y
text2=rule1 { if( text1.equals( text2 ) ) System.out.println( "==" ); }
;
Regards,
Alexey
-----
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com
----- Original Message -----
From: "Andrew Bell" <andrew.bell.ia at gmail.com>
To: <antlr-interest at antlr.org>
Sent: Tuesday, March 07, 2006 3:34 AM
Subject: [antlr-interest] Extracting match
> Hi,
>
> I've got a grammar that looks something like:
>
> rule1 : "foo" | "bar" | "baz"
> ;
>
> rule2 : x rule1 y rule1
> ;
>
> I want to know in rule2 which of the strings "foo", "bar" or "baz"
> were matched. Can someone show me the preferred way to do this?
>
> Thanks,
>
> --
> Andrew Bell
> andrew.bell.ia at gmail.com
More information about the antlr-interest
mailing list