KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > beaver > spec > ast > Rule


1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * This file is part of Beaver Parser Generator. *
3  * Copyright (C) 2003,2004 Alexander Demenchuk <alder@softanvil.com>. *
4  * All rights reserved. *
5  * See the file "LICENSE" for the terms and conditions for copying, *
6  * distribution and modification of Beaver. *
7  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

8
9 package beaver.spec.ast;
10
11 import beaver.Symbol;
12
13 public class Rule extends Node
14 {
15     static public class Definition extends Node
16     {
17         static public class Element extends Node
18         {
19             public final Symbol sym_name;
20             public final Symbol alias;
21             public final Symbol ebnf_sym;
22             
23             public Element(Symbol sym_name, Symbol alias, Symbol ebnf_sym)
24             {
25                 this.sym_name = sym_name;
26                 this.alias = alias;
27                 this.ebnf_sym = ebnf_sym;
28             }
29             
30             public void accept(TreeWalker walker)
31             {
32                 walker.visit(this);
33             }
34             
35             public String JavaDoc getName()
36             {
37                 return (String JavaDoc) sym_name.value;
38             }
39             
40             public String JavaDoc getAlias()
41             {
42                 return (String JavaDoc) alias.value;
43             }
44             
45             public char getExtUseMark()
46             {
47                 return ebnf_sym.value == null ? ' ' : ((String JavaDoc) ebnf_sym.value).charAt(0);
48             }
49         }
50         
51         public final Element[] elements;
52         public final Symbol prec_sym_name;
53         public final Symbol code;
54         
55         public Definition(Element[] elts, Symbol prec_sym_name, Symbol code)
56         {
57             this.elements = elts;
58             this.prec_sym_name = prec_sym_name;
59             this.code = code;
60         }
61         
62         public Definition(Element[] elts)
63         {
64             this.elements = elts;
65             this.prec_sym_name = null;
66             this.code = null;
67         }
68         
69         public void accept(TreeWalker walker)
70         {
71             walker.visit(this);
72         }
73         
74         public String JavaDoc getPrecedenceSymbolName()
75         {
76             return (String JavaDoc) prec_sym_name.value;
77         }
78         
79         public String JavaDoc getReduceActionCode()
80         {
81             return (String JavaDoc) code.value;
82         }
83     }
84     
85     public final Symbol lhs_sym;
86     public final Definition[] defs;
87     
88     public Rule(Symbol lhs_sym, Rule.Definition[] defs)
89     {
90         this.lhs_sym = lhs_sym;
91         this.defs = defs;
92     }
93     
94     public String JavaDoc getLHSSymbolName()
95     {
96         return (String JavaDoc) lhs_sym.value;
97     }
98     
99     public void accept(TreeWalker walker)
100     {
101         walker.visit(this);
102     }
103 }
104
Popular Tags