tree grammar FunctionID; options{ tokenVocab = SampleC; ASTLabelType = CommonTree; } @header{ import java.util.ArrayList; import java.util.List; } program : ^(PROGRAM definition+ . // block ) EOF ; definition : functionDefintion | ^(VARDEF INT i=IDENTIFIER) ; functionDefintion scope { String label; } @after{ CommonTree blockNode = (CommonTree)$functionDefintion.start.getChild(4); Engine.symtab.declareFunction($i.text, "int", $p.parmList, blockNode); } : ^(FUNC INT i=IDENTIFIER ^(FUNCPAR p=parameterList) . // parameterDeclarations . // block ) ; parameterList returns[List parmList] @init{ parmList = new ArrayList(); } : ( i=IDENTIFIER {parmList.add($i.text);} )* ;