1	package antlr;
2	
3	/**
4	 * <b>SOFTWARE RIGHTS</b>
5	 * <p>
6	 * ANTLR 2.5.0 MageLang Institute, 1998
7	 * <p>
8	 * We reserve no legal rights to the ANTLR--it is fully in the
9	 * public domain. An individual or company may do whatever
10	 * they wish with source code distributed with ANTLR or the
11	 * code generated by ANTLR, including the incorporation of
12	 * ANTLR, or its output, into commerical software.
13	 * <p>
14	 * We encourage users to develop software with ANTLR. However,
15	 * we do ask that credit is given to us for developing
16	 * ANTLR. By "credit", we mean that if you use ANTLR or
17	 * incorporate any source code into one of your programs
18	 * (commercial product, research project, or otherwise) that
19	 * you acknowledge this fact somewhere in the documentation,
20	 * research report, etc... If you like ANTLR and have
21	 * developed a nice tool with the output, please mention that
22	 * you developed it using ANTLR. In addition, we ask that the
23	 * headers remain intact in our source code. As long as these
24	 * guidelines are kept, we expect to continue enhancing this
25	 * system and expect to make other tools available as they are
26	 * completed.
27	 * <p>
28	 * The ANTLR gang:
29	 * @version ANTLR 2.5.0 MageLang Institute, 1998
30	 * @author Terence Parr, <a href=http://www.MageLang.com>MageLang Institute</a>
31	 * @author <br>John Lilley, <a href=http://www.Empathy.com>Empathy Software</a>
32	 */
33	
34	import java.util.Hashtable;
35	import java.util.Enumeration;
36	import java.io.IOException;
37	import antlr.collections.impl.BitSet;
38	import antlr.collections.impl.Vector;
39	
40	
41	/** Parser-specific grammar subclass */
42	class ParserGrammar extends Grammar {
43	
44	
45		ParserGrammar(String className_, Tool tool_, String superClass) {
46			super(className_, tool_, superClass);
47		}
48		/** Top-level call to generate the code for this grammar */
49		public void generate() throws IOException {
50			generator.gen(this);
51		}
52		// Get name of class from which generated parser/lexer inherits
53		protected String getSuperClass() {
54			// if debugging, choose the debugging version of the parser
55			if (debuggingOutput)
56				return "debug.LLkDebuggingParser";
57			return "LLkParser"; 
58		}
59		/**Process command line arguments.
60		 * -trace			have all rules call traceIn/traceOut
61		 * -traceParser		have parser rules call traceIn/traceOut
62		 * -debug			generate debugging output for parser debugger
63		 */
64		public void processArguments(String[] args) {
65			for (int i=0; i<args.length; i++) {
66				if ( args[i].equals("-trace") ) {
67					traceRules = true;
68					Tool.setArgOK(i);
69				}
70				else if ( args[i].equals("-traceParser") ) {
71					traceRules = true;
72					Tool.setArgOK(i);
73				}
74				else if ( args[i].equals("-debug") ) {
75					debuggingOutput = true;
76					Tool.setArgOK(i);
77				}
78			}
79		}
80		/** Set parser options -- performs action on the following options:
81		  */
82		public boolean setOption(String key, Token value) {
83			String s = value.getText();
84			if (key.equals("buildAST")) {
85				if (s.equals("true")) {
86					buildAST = true;
87				} else if (s.equals("false")) {
88					buildAST = false;
89				} else {
90					tool.error("buildAST option must be true or false", value.getLine());
91				}
92				return true;
93			}
94			if (key.equals("interactive")) {
95				if (s.equals("true")) {
96					interactive = true;
97				} else if (s.equals("false")) {
98					interactive = false;
99				} else {
100					tool.error("interactive option must be true or false", value.getLine());
101				}
102				return true;
103			}
104			if (key.equals("ASTLabelType")) {
105				super.setOption(key, value);
106				return true;
107			}	
108			if (super.setOption(key, value)) {
109				return true;
110			}
111			tool.error("Invalid option: " + key, value.getLine());
112			return false;
113		}
114	}
115