make T.g same

This commit is contained in:
Terence Parr 2012-03-14 13:20:24 -07:00
parent 28ee391c81
commit 102980dffd
1 changed files with 8 additions and 23 deletions

View File

@ -1,24 +1,9 @@
grammar T;
@members {
public static class LeafListener extends TBaseListener {
public void exitCall(TParser.CallContext ctx) {
System.out.printf("%s %s",ctx.e().start.getText(),
ctx.eList());
}
} public void exitInt(TParser.IntContext ctx) {
System.out.println(ctx.INT().getText());
}
}
s
@init {setBuildParseTree(true);}
@after { System.out.println($r.ctx.toStringTree(this)); ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(new LeafListener(), $r.ctx);}
: r=e ;
e : e '(' eList ')' -> Call
| INT -> Int
s : a a a;
a : {false}? ID
| {true}? ID
| INT
;
eList : e (',' e)* ;
MULT: '*' ;
ADD : '+' ;
INT : [0-9]+ ;
WS : [ \t\n]+ -> skip ;
ID : 'a'..'z'+ ;
INT : '0'..'9'+;
WS : (' '|'\n') {skip();} ;