字句解析:TOKEN_MGR_DECLS
PARSER_BEGIN(Test) public class Test { public static void main(String args[]) throws ParseException { Test parser = new Test(System.in); parser.Input(); } } PARSER_END(Test) TOKEN_MGR_DECLS : { static int x = 1; } SKIP : { <SPACE: " " | "\t" | "\n" | "\r"> } TOKEN : { <A: "a"> { System.out.println("*" + x++ + "*"); } } void Input() : {} { ( <A> )+ <EOF> }
で、
a *1* a *2* a *3*