1 package antlr; 2 3 9 10 import java.util.Hashtable ; 11 import java.util.Enumeration ; 12 import java.io.IOException ; 13 14 import antlr.collections.impl.BitSet; 15 import antlr.collections.impl.Vector; 16 17 18 19 class ParserGrammar extends Grammar { 20 21 22 ParserGrammar(String className_, Tool tool_, String superClass) { 23 super(className_, tool_, superClass); 24 } 25 26 27 public void generate() throws IOException { 28 generator.gen(this); 29 } 30 31 protected String getSuperClass() { 33 if (debuggingOutput) 35 return "debug.LLkDebuggingParser"; 36 return "LLkParser"; 37 } 38 39 44 public void processArguments(String [] args) { 45 for (int i = 0; i < args.length; i++) { 46 if (args[i].equals("-trace")) { 47 traceRules = true; 48 antlrTool.setArgOK(i); 49 } 50 else if (args[i].equals("-traceParser")) { 51 traceRules = true; 52 antlrTool.setArgOK(i); 53 } 54 else if (args[i].equals("-debug")) { 55 debuggingOutput = true; 56 antlrTool.setArgOK(i); 57 } 58 } 59 } 60 61 63 public boolean setOption(String key, Token value) { 64 String s = value.getText(); 65 if (key.equals("buildAST")) { 66 if (s.equals("true")) { 67 buildAST = true; 68 } 69 else if (s.equals("false")) { 70 buildAST = false; 71 } 72 else { 73 antlrTool.error("buildAST option must be true or false", getFilename(), value.getLine(), value.getColumn()); 74 } 75 return true; 76 } 77 if (key.equals("interactive")) { 78 if (s.equals("true")) { 79 interactive = true; 80 } 81 else if (s.equals("false")) { 82 interactive = false; 83 } 84 else { 85 antlrTool.error("interactive option must be true or false", getFilename(), value.getLine(), value.getColumn()); 86 } 87 return true; 88 } 89 if (key.equals("ASTLabelType")) { 90 super.setOption(key, value); 91 return true; 92 } 93 if (super.setOption(key, value)) { 94 return true; 95 } 96 antlrTool.error("Invalid option: " + key, getFilename(), value.getLine(), value.getColumn()); 97 return false; 98 } 99 } 100 | Popular Tags |