KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > persistence > antlr > GrammarAtom


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 GrammarAtom is either a token ref, a character ref, or string.
10  * The analysis doesn't care.
11  */

12 abstract class GrammarAtom extends AlternativeElement {
13     protected String JavaDoc label;
14     protected String JavaDoc atomText;
15     protected int tokenType = Token.INVALID_TYPE;
16     protected boolean not = false; // ~T or ~'c' or ~"foo"
17
/** Set to type of AST node to create during parse. Defaults to what is
18      * set in the TokenSymbol.
19      */

20     protected String JavaDoc ASTNodeType = null;
21
22     public GrammarAtom(Grammar g, Token t, int autoGenType) {
23         super(g, t, autoGenType);
24         atomText = t.getText();
25     }
26
27     public String JavaDoc getLabel() {
28         return label;
29     }
30
31     public String JavaDoc getText() {
32         return atomText;
33     }
34
35     public int getType() {
36         return tokenType;
37     }
38
39     public void setLabel(String JavaDoc label_) {
40         label = label_;
41     }
42
43     public String JavaDoc getASTNodeType() {
44         return ASTNodeType;
45     }
46
47     public void setASTNodeType(String JavaDoc type) {
48         ASTNodeType = type;
49     }
50
51     public void setOption(Token option, Token value) {
52         if (option.getText().equals("AST")) {
53             setASTNodeType(value.getText());
54         }
55         else {
56             grammar.antlrTool.error("Invalid element option:" + option.getText(),
57                                grammar.getFilename(), option.getLine(), option.getColumn());
58         }
59     }
60
61     public String JavaDoc toString() {
62         String JavaDoc s = " ";
63         if (label != null) s += label + ":";
64         if (not) s += "~";
65         return s + atomText;
66     }
67 }
68
Popular Tags