01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2007 Robert Grimm
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * version 2 as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17: * USA.
18: */
19: package xtc.tree;
20:
21: /**
22: * Visitor to print parse trees.
23: *
24: * @author Robert Grimm
25: * @version $Revision: 1.3 $
26: */
27: public class ParseTreePrinter extends Visitor {
28:
29: /** The printer. */
30: protected final Printer printer;
31:
32: /**
33: * Create a new parse tree printer.
34: *
35: * @param printer The printer.
36: */
37: public ParseTreePrinter(Printer printer) {
38: this .printer = printer;
39: printer.register(this );
40: }
41:
42: /** Print the specified generic node. */
43: public void visit(GNode n) {
44: for (Object o : n) {
45: if (o instanceof Node)
46: dispatch((Node) o);
47: }
48: }
49:
50: /** Print the specified formatting node. */
51: public void visit(Formatting f) {
52: for (Object o : f) {
53: if (o instanceof Node)
54: dispatch((Node) o);
55: }
56: }
57:
58: /** Print the specified token. */
59: public void visit(Token t) {
60: printer.p(t.getTokenText());
61: }
62:
63: }
|