KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > persistence > antlr > GrammarElement


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 /**A GrammarElement is a generic node in our
10  * data structure that holds a grammar in memory.
11  * This data structure can be used for static
12  * analysis or for dynamic analysis (during parsing).
13  * Every node must know which grammar owns it, how
14  * to generate code, and how to do analysis.
15  */

16 abstract class GrammarElement {
17     public static final int AUTO_GEN_NONE = 1;
18     public static final int AUTO_GEN_CARET = 2;
19     public static final int AUTO_GEN_BANG = 3;
20
21     /*
22      * Note that Java does static argument type matching to
23      * determine which function to execute on the receiver.
24      * Here, that implies that we cannot simply say
25      * grammar.generator.gen(this) in GrammarElement or
26      * only CodeGenerator.gen(GrammarElement ge) would
27      * ever be called.
28      */

29     protected Grammar grammar;
30     protected int line;
31     protected int column;
32
33     public GrammarElement(Grammar g) {
34         grammar = g;
35         line = -1;
36         column = -1;
37     }
38
39     public GrammarElement(Grammar g, Token start) {
40         grammar = g;
41         line = start.getLine();
42         column = start.getColumn();
43     }
44
45     public void generate() {
46     }
47
48     public int getLine() {
49         return line;
50     }
51
52     public int getColumn() {
53         return column;
54     }
55
56     public Lookahead look(int k) {
57         return null;
58     }
59
60     public abstract String JavaDoc toString();
61 }
62
Popular Tags