KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > persistence > antlr > TreeWalkerGrammar


1 package persistence.antlr;
2
3 /* ANTLR Translator Generator
4  * Project led by Terence Parr at http://www.jGuru.com
5  * Software rights: http://www.antlr.org/license.html
6  *
7  */

8
9 import java.util.Hashtable JavaDoc;
10 import java.util.Enumeration JavaDoc;
11 import java.io.IOException JavaDoc;
12
13 import persistence.antlr.collections.impl.BitSet;
14 import persistence.antlr.collections.impl.Vector;
15
16
17 /** Parser-specific grammar subclass */
18 class TreeWalkerGrammar extends Grammar {
19     // true for transform mode
20
protected boolean transform = false;
21
22
23     TreeWalkerGrammar(String JavaDoc className_, Tool tool_, String JavaDoc superClass) {
24         super(className_, tool_, superClass);
25     }
26
27     /** Top-level call to generate the code for this grammar */
28     public void generate() throws IOException JavaDoc {
29         generator.gen(this);
30     }
31
32     // Get name of class from which generated parser/lexer inherits
33
protected String JavaDoc getSuperClass() {
34         return "TreeParser";
35     }
36
37     /**Process command line arguments.
38      * -trace have all rules call traceIn/traceOut
39      * -traceParser have parser rules call traceIn/traceOut
40      * -debug generate debugging output for parser debugger
41      */

42     public void processArguments(String JavaDoc[] args) {
43         for (int i = 0; i < args.length; i++) {
44             if (args[i].equals("-trace")) {
45                 traceRules = true;
46                 antlrTool.setArgOK(i);
47             }
48             else if (args[i].equals("-traceTreeParser")) {
49                 traceRules = true;
50                 antlrTool.setArgOK(i);
51             }
52 // else if ( args[i].equals("-debug") ) {
53
// debuggingOutput = true;
54
// superClass = "parseview.DebuggingTreeWalker";
55
// Tool.setArgOK(i);
56
// }
57
}
58     }
59
60     /** Set tree parser options */
61     public boolean setOption(String JavaDoc key, Token value) {
62         if (key.equals("buildAST")) {
63             if (value.getText().equals("true")) {
64                 buildAST = true;
65             }
66             else if (value.getText().equals("false")) {
67                 buildAST = false;
68             }
69             else {
70                 antlrTool.error("buildAST option must be true or false", getFilename(), value.getLine(), value.getColumn());
71             }
72             return true;
73         }
74         if (key.equals("ASTLabelType")) {
75             super.setOption(key, value);
76             return true;
77         }
78         if (super.setOption(key, value)) {
79             return true;
80         }
81         antlrTool.error("Invalid option: " + key, getFilename(), value.getLine(), value.getColumn());
82         return false;
83     }
84 }
85
Popular Tags