1tree grammar t047treeparserWalker; 2options { 3 language=Python; 4 tokenVocab=t047treeparser; 5 ASTLabelType=CommonTree; 6} 7 8program 9 : declaration+ 10 ; 11 12declaration 13 : variable 14 | ^(FUNC_DECL functionHeader) 15 | ^(FUNC_DEF functionHeader block) 16 ; 17 18variable returns [res] 19 : ^(VAR_DEF type declarator) 20 { 21 $res = $declarator.text; 22 } 23 ; 24 25declarator 26 : ID 27 ; 28 29functionHeader 30 : ^(FUNC_HDR type ID formalParameter+) 31 ; 32 33formalParameter 34 : ^(ARG_DEF type declarator) 35 ; 36 37type 38 : 'int' 39 | 'char' 40 | 'void' 41 | ID 42 ; 43 44block 45 : ^(BLOCK variable* stat*) 46 ; 47 48stat: forStat 49 | expr 50 | block 51 ; 52 53forStat 54 : ^('for' expr expr expr block) 55 ; 56 57expr: ^(EQEQ expr expr) 58 | ^(LT expr expr) 59 | ^(PLUS expr expr) 60 | ^(EQ ID expr) 61 | atom 62 ; 63 64atom 65 : ID 66 | INT 67 ; 68