KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > antlr > RuleRefElement


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/RuleRefElement.java#6 $
8  */

9
10 class RuleRefElement extends AlternativeElement {
11     protected String JavaDoc targetRule; // which rule is being called?
12
protected String JavaDoc args = null; // were any args passed to rule?
13
protected String JavaDoc idAssign = null; // is the return type assigned to a variable?
14
protected String JavaDoc label;
15
16
17     public RuleRefElement(Grammar g, Token t, int autoGenType_) {
18         super(g, t, autoGenType_);
19         targetRule = t.getText();
20         // if ( Character.isUpperCase(targetRule.charAt(0)) ) { // lexer rule?
21
if (t.type == ANTLRTokenTypes.TOKEN_REF) { // lexer rule?
22
targetRule = CodeGenerator.encodeLexerRuleName(targetRule);
23         }
24     }
25
26 // public RuleRefElement(Grammar g, String t, int line, int autoGenType_) {
27
// super(g, autoGenType_);
28
// targetRule = t;
29
// if ( Character.isUpperCase(targetRule.charAt(0)) ) { // lexer rule?
30
// targetRule = CodeGenerator.lexerRuleName(targetRule);
31
// }
32
// this.line = line;
33
// }
34

35     public void generate() {
36         grammar.generator.gen(this);
37     }
38
39     public String JavaDoc getArgs() {
40         return args;
41     }
42
43     public String JavaDoc getIdAssign() {
44         return idAssign;
45     }
46
47     public String JavaDoc getLabel() {
48         return label;
49     }
50
51     public Lookahead look(int k) {
52         return grammar.theLLkAnalyzer.look(k, this);
53     }
54
55     public void setArgs(String JavaDoc a) {
56         args = a;
57     }
58
59     public void setIdAssign(String JavaDoc id) {
60         idAssign = id;
61     }
62
63     public void setLabel(String JavaDoc label_) {
64         label = label_;
65     }
66
67     public String JavaDoc toString() {
68         if (args != null)
69             return " " + targetRule + args;
70         else
71             return " " + targetRule;
72     }
73 }
74
Popular Tags