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