2011-09-23 09:16:22 +08:00
|
|
|
grammar U;
|
2012-06-08 08:31:18 +08:00
|
|
|
|
|
|
|
@members {public static boolean java5 = true;}
|
|
|
|
|
|
|
|
prog: ( enumDecl
|
|
|
|
| stat
|
|
|
|
)*
|
|
|
|
EOF
|
|
|
|
;
|
|
|
|
|
|
|
|
enumDecl
|
|
|
|
: {java5}? 'enum' ID '{' ID (',' ID)* '}'
|
|
|
|
;
|
|
|
|
|
|
|
|
args
|
|
|
|
: arg (',' arg )*
|
|
|
|
;
|
|
|
|
|
|
|
|
arg
|
|
|
|
: INT
|
|
|
|
;
|
|
|
|
|
|
|
|
stat: ID '=' expr ';' ;
|
|
|
|
|
|
|
|
expr: ID {System.out.println("ID "+$ID.text);}
|
|
|
|
| {!java5}? 'enum' {System.out.println("ID enum");}
|
|
|
|
| INT
|
|
|
|
;
|
|
|
|
|
|
|
|
ID : [a-zA-Z]+ ;
|
|
|
|
INT : [0-9]+ ;
|
|
|
|
WS : [ \t\n\r]+ -> skip ;
|