KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > antlr > GrammarAtom


1 package antlr;
2
3 /* ANTLR Translator Generator
4  * Project led by Terence Parr at http://www.jGuru.com
5  * Software rights: http://www.antlr.org/RIGHTS.html
6  *
7  * $Id: //depot/code/org.antlr/main/main/antlr/GrammarAtom.java#6 $
8  */

9
10 /** A GrammarAtom is either a token ref, a character ref, or string.
11  * The analysis doesn't care.
12  */

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

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