001: package antlr;
002:
003: /* ANTLR Translator Generator
004: * Project led by Terence Parr at http://www.cs.usfca.edu
005: * Software rights: http://www.antlr.org/license.html
006: */
007:
008: import java.util.Hashtable;
009: import java.util.Enumeration;
010: import java.io.IOException;
011:
012: import antlr.collections.impl.BitSet;
013: import antlr.collections.impl.Vector;
014:
015: /** Parser-specific grammar subclass */
016: class ParserGrammar extends Grammar {
017:
018: ParserGrammar(String className_, Tool tool_, String super Class) {
019: super (className_, tool_, super Class);
020: }
021:
022: /** Top-level call to generate the code for this grammar */
023: public void generate() throws IOException {
024: generator.gen(this );
025: }
026:
027: // Get name of class from which generated parser/lexer inherits
028: protected String getSuperClass() {
029: // if debugging, choose the debugging version of the parser
030: if (debuggingOutput)
031: return "debug.LLkDebuggingParser";
032: if (!MatchExceptionState.throwRecExceptions)
033: return "LLkParserNoEx";
034: return "LLkParser";
035: }
036:
037: /**Process command line arguments.
038: * -trace have all rules call traceIn/traceOut
039: * -traceParser have parser rules call traceIn/traceOut
040: * -debug generate debugging output for parser debugger
041: */
042: public void processArguments(String[] args) {
043: for (int i = 0; i < args.length; i++) {
044: if (args[i].equals("-trace")) {
045: traceRules = true;
046: antlrTool.setArgOK(i);
047: } else if (args[i].equals("-traceParser")) {
048: traceRules = true;
049: antlrTool.setArgOK(i);
050: } else if (args[i].equals("-debug")) {
051: debuggingOutput = true;
052: antlrTool.setArgOK(i);
053: }
054: }
055: }
056:
057: /** Set parser options -- performs action on the following options:
058: */
059: public boolean setOption(String key, Token value) {
060: String s = value.getText();
061: if (key.equals("buildAST")) {
062: if (s.equals("true")) {
063: buildAST = true;
064: } else if (s.equals("false")) {
065: buildAST = false;
066: } else {
067: antlrTool.error(
068: "buildAST option must be true or false",
069: getFilename(), value.getLine(), value
070: .getColumn());
071: }
072: return true;
073: }
074: if (key.equals("interactive")) {
075: if (s.equals("true")) {
076: interactive = true;
077: } else if (s.equals("false")) {
078: interactive = false;
079: } else {
080: antlrTool.error(
081: "interactive option must be true or false",
082: getFilename(), value.getLine(), value
083: .getColumn());
084: }
085: return true;
086: }
087: if (key.equals("ASTLabelType")) {
088: super .setOption(key, value);
089: return true;
090: }
091: if (key.equals("className")) {
092: super .setOption(key, value);
093: return true;
094: }
095: if (super .setOption(key, value)) {
096: return true;
097: }
098: antlrTool.error("Invalid option: " + key, getFilename(), value
099: .getLine(), value.getColumn());
100: return false;
101: }
102: }
|