01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2004-2005 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.parser;
20:
21: import xtc.util.Runtime;
22:
23: /**
24: * Visitor to rename nonterminals.
25: *
26: * @author Robert Grimm
27: * @version $Revision: 1.5 $
28: */
29: public class Renamer extends GrammarVisitor {
30:
31: /**
32: * The interface to the actual mapping from nonterminals to
33: * nonterminals.
34: */
35: public interface Translation {
36:
37: /**
38: * Map the specified nonterminal to its replacement, which may be
39: * the same as the original.
40: *
41: * @param nt The nonterminal.
42: * @param analyzer The analyzer utility.
43: * @return The translated nonterminal.
44: */
45: public NonTerminal map(NonTerminal nt, Analyzer analyzer);
46:
47: }
48:
49: // -----------------------------------------------------------------------
50:
51: /** The mapping. */
52: protected Translation translation;
53:
54: /**
55: * Create a new renamer.
56: *
57: * @param runtime The runtime.
58: * @param analyzer The analyzer utility.
59: * @param translation The mapping from nonterminals to nonterminals.
60: */
61: public Renamer(Runtime runtime, Analyzer analyzer,
62: Translation translation) {
63: super (runtime, analyzer);
64: this .translation = translation;
65: }
66:
67: /** Visit the specified nonterminal. */
68: public Element visit(NonTerminal nt) {
69: return translation.map(nt, analyzer);
70: }
71:
72: }
|