01: package persistence.antlr;
02:
03: /* ANTLR Translator Generator
04: * Project led by Terence Parr at http://www.jGuru.com
05: * Software rights: http://www.antlr.org/license.html
06: *
07: */
08:
09: import java.util.Hashtable;
10: import java.util.Enumeration;
11: import java.io.IOException;
12:
13: import persistence.antlr.collections.impl.BitSet;
14: import persistence.antlr.collections.impl.Vector;
15:
16: /** Parser-specific grammar subclass */
17: class TreeWalkerGrammar extends Grammar {
18: // true for transform mode
19: protected boolean transform = false;
20:
21: TreeWalkerGrammar(String className_, Tool tool_, String super Class) {
22: super (className_, tool_, super Class);
23: }
24:
25: /** Top-level call to generate the code for this grammar */
26: public void generate() throws IOException {
27: generator.gen(this );
28: }
29:
30: // Get name of class from which generated parser/lexer inherits
31: protected String getSuperClass() {
32: return "TreeParser";
33: }
34:
35: /**Process command line arguments.
36: * -trace have all rules call traceIn/traceOut
37: * -traceParser have parser rules call traceIn/traceOut
38: * -debug generate debugging output for parser debugger
39: */
40: public void processArguments(String[] args) {
41: for (int i = 0; i < args.length; i++) {
42: if (args[i].equals("-trace")) {
43: traceRules = true;
44: antlrTool.setArgOK(i);
45: } else if (args[i].equals("-traceTreeParser")) {
46: traceRules = true;
47: antlrTool.setArgOK(i);
48: }
49: // else if ( args[i].equals("-debug") ) {
50: // debuggingOutput = true;
51: // superClass = "parseview.DebuggingTreeWalker";
52: // Tool.setArgOK(i);
53: // }
54: }
55: }
56:
57: /** Set tree parser options */
58: public boolean setOption(String key, Token value) {
59: if (key.equals("buildAST")) {
60: if (value.getText().equals("true")) {
61: buildAST = true;
62: } else if (value.getText().equals("false")) {
63: buildAST = false;
64: } else {
65: antlrTool.error(
66: "buildAST option must be true or false",
67: getFilename(), value.getLine(), value
68: .getColumn());
69: }
70: return true;
71: }
72: if (key.equals("ASTLabelType")) {
73: super .setOption(key, value);
74: return true;
75: }
76: if (super .setOption(key, value)) {
77: return true;
78: }
79: antlrTool.error("Invalid option: " + key, getFilename(), value
80: .getLine(), value.getColumn());
81: return false;
82: }
83: }
|