public void visit(NodeListOptional n, String sep) { if (n.present()) for (Enumeration e = n.elements(); e.hasMoreElements(); ) { ((Node) e.nextElement()).accept(this); if (e.hasMoreElements()) out.print(sep); } }
// // For convenience, trusts that the node passed to it is a NodeSequence. // (of course, will throw an exception if it isn't). // public void visit(Node n1, String sep) { NodeSequence n = (NodeSequence) n1; for (Enumeration e = n.elements(); e.hasMoreElements(); ) { ((Node) e.nextElement()).accept(this); if (e.hasMoreElements()) out.print(sep); } }
// // f0 -> "try" // f1 -> Block() // f2 -> ( "catch" "(" FormalParameter() ")" Block() )* // f3 -> [ "finally" Block() ] // public void visit(TryStatement n) { out.println(n.f0); out.print(spc.spc); n.f1.accept(this); for (Enumeration e = n.f2.elements(); e.hasMoreElements(); ) { NodeSequence seq = (NodeSequence) e.nextElement(); out.println(); out.print(spc.spc); seq.elementAt(0).accept(this); out.print(" "); seq.elementAt(1).accept(this); seq.elementAt(2).accept(this); seq.elementAt(3).accept(this); out.println(); out.print(spc.spc); seq.elementAt(4).accept(this); } if (n.f3.present()) { NodeSequence seq = (NodeSequence) n.f3.node; out.println(); seq.elementAt(0).accept(this); out.println(); out.print(spc.spc); seq.elementAt(1).accept(this); } }
// // f0 -> "switch" // f1 -> "(" // f2 -> Expression() // f3 -> ")" // f4 -> "{" // f5 -> ( SwitchLabel() ( BlockStatement() )* )* // f6 -> "}" // public void visit(SwitchStatement n) { out.print(n.f0 + " " + n.f1); n.f2.accept(this); out.println(n.f3); out.println(spc.spc + n.f4); spc.updateSpc(+1); for (Enumeration e = n.f5.elements(); e.hasMoreElements(); ) { NodeSequence seq = (NodeSequence) e.nextElement(); out.print(spc.spc); seq.elementAt(0).accept(this); spc.updateSpc(+1); if (((NodeListOptional) seq.elementAt(1)).present()) { if (((NodeListOptional) seq.elementAt(1)).size() == 1) out.print(" "); else { out.println(); out.print(spc.spc); } visit((NodeListOptional) seq.elementAt(1), "\n" + spc.spc); } out.println(); spc.updateSpc(-1); } spc.updateSpc(-1); out.println(spc.spc + n.f6); }
// // f0 -> UnaryExpression() // f1 -> ( ( "*"| "/" | "%" ) UnaryExpression() )* // public void visit(MultiplicativeExpression n) { n.f0.accept(this); if (n.f1.present()) { out.print(" "); for (Enumeration e = n.f1.elements(); e.hasMoreElements(); ) visit((Node) e.nextElement(), " "); } }