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 ParserGrammar extends Grammar {
18:
19: ParserGrammar(String className_, Tool tool_, String super Class) {
20: super (className_, tool_, super Class);
21: }
22:
23: /** Top-level call to generate the code for this grammar */
24: public void generate() throws IOException {
25: generator.gen(this );
26: }
27:
28: // Get name of class from which generated parser/lexer inherits
29: protected String getSuperClass() {
30: // if debugging, choose the debugging version of the parser
31: if (debuggingOutput)
32: return "debug.LLkDebuggingParser";
33: return "LLkParser";
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("-traceParser")) {
47: traceRules = true;
48: antlrTool.setArgOK(i);
49: } else if (args[i].equals("-debug")) {
50: debuggingOutput = true;
51: antlrTool.setArgOK(i);
52: }
53: }
54: }
55:
56: /** Set parser options -- performs action on the following options:
57: */
58: public boolean setOption(String key, Token value) {
59: String s = value.getText();
60: if (key.equals("buildAST")) {
61: if (s.equals("true")) {
62: buildAST = true;
63: } else if (s.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("interactive")) {
74: if (s.equals("true")) {
75: interactive = true;
76: } else if (s.equals("false")) {
77: interactive = false;
78: } else {
79: antlrTool.error(
80: "interactive option must be true or false",
81: getFilename(), value.getLine(), value
82: .getColumn());
83: }
84: return true;
85: }
86: if (key.equals("ASTLabelType")) {
87: super .setOption(key, value);
88: return true;
89: }
90: if (super .setOption(key, value)) {
91: return true;
92: }
93: antlrTool.error("Invalid option: " + key, getFilename(), value
94: .getLine(), value.getColumn());
95: return false;
96: }
97: }
|