开发者

Print matched token in JavaCC

开发者 https://www.devze.com 2022-12-17 08:00 出处:网络
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:

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 t开发者_JS百科o output, given some input, let's say 5, is:

I recognize that BLAH is 5.

Any tips? Thanks


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); } ) 
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号