tags:

views:

87

answers:

1

I need to print the token that was matched by javacc, but I don't know how to "store it". Let's say my token definition is:

TOKEN :
{
    < BLAH: ["0"-"9"]> 
}

and my parser.input() function is:

void Input():
{}
{ (<BLAH> { System.out.println("I recognize BLAH"); } ) 
}

However what I really want to output, given some input, let's say 5, is:

I recognize that BLAH is 5.

Any tips? Thanks

A: 

Basically you declare variables in the first curly braces and use them in the second:

void Input():
{ Token t;   }
{ 
   (t=<BLAH> { System.out.println("I recognize BLAH is "  + t.image); } ) 
}
drozzy