1 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 getName() 36 { 37 return (String ) sym_name.value; 38 } 39 40 public String getAlias() 41 { 42 return (String ) alias.value; 43 } 44 45 public char getExtUseMark() 46 { 47 return ebnf_sym.value == null ? ' ' : ((String ) 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 getPrecedenceSymbolName() 75 { 76 return (String ) prec_sym_name.value; 77 } 78 79 public String getReduceActionCode() 80 { 81 return (String ) 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 getLHSSymbolName() 95 { 96 return (String ) lhs_sym.value; 97 } 98 99 public void accept(TreeWalker walker) 100 { 101 walker.visit(this); 102 } 103 } 104 | Popular Tags |