package step7; import java.util.List; import step7.expr.yyLex; /** output {@link expr} tree in postfix notation. */ public class postfix implements jag.Visitor { %% List: Object Object { {$1}; {$2}; `" "+classname($0)`; } | Object { {$1}; `" "+classname($0)`; }; Number: { `" "+$0`; }; %% /** return last component of (inner) classname. */ protected static String classname (Object obj) { String name = obj.getClass().getName(); return name.substring(name.lastIndexOf("$")+1); } /** read an expression from standard input and output it in postorder. */ public static void main (String[] args) throws Exception { new postfix().visit(new expr().yyparse(new yyLex(System.in))); System.out.println(); } }