01: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
02: * This file is part of Beaver Parser Generator. *
03: * Copyright (C) 2003,2004 Alexander Demenchuk <alder@softanvil.com>. *
04: * All rights reserved. *
05: * See the file "LICENSE" for the terms and conditions for copying, *
06: * distribution and modification of Beaver. *
07: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
08:
09: package beaver.spec.ast;
10:
11: import beaver.Symbol;
12:
13: public class Rule extends Node {
14: static public class Definition extends Node {
15: static public class Element extends Node {
16: public final Symbol sym_name;
17: public final Symbol alias;
18: public final Symbol ebnf_sym;
19:
20: public Element(Symbol sym_name, Symbol alias,
21: Symbol ebnf_sym) {
22: this .sym_name = sym_name;
23: this .alias = alias;
24: this .ebnf_sym = ebnf_sym;
25: }
26:
27: public void accept(TreeWalker walker) {
28: walker.visit(this );
29: }
30:
31: public String getName() {
32: return (String) sym_name.value;
33: }
34:
35: public String getAlias() {
36: return (String) alias.value;
37: }
38:
39: public char getExtUseMark() {
40: return ebnf_sym.value == null ? ' '
41: : ((String) ebnf_sym.value).charAt(0);
42: }
43: }
44:
45: public final Element[] elements;
46: public final Symbol prec_sym_name;
47: public final Symbol code;
48:
49: public Definition(Element[] elts, Symbol prec_sym_name,
50: Symbol code) {
51: this .elements = elts;
52: this .prec_sym_name = prec_sym_name;
53: this .code = code;
54: }
55:
56: public Definition(Element[] elts) {
57: this .elements = elts;
58: this .prec_sym_name = null;
59: this .code = null;
60: }
61:
62: public void accept(TreeWalker walker) {
63: walker.visit(this );
64: }
65:
66: public String getPrecedenceSymbolName() {
67: return (String) prec_sym_name.value;
68: }
69:
70: public String getReduceActionCode() {
71: return (String) code.value;
72: }
73: }
74:
75: public final Symbol lhs_sym;
76: public final Definition[] defs;
77:
78: public Rule(Symbol lhs_sym, Rule.Definition[] defs) {
79: this .lhs_sym = lhs_sym;
80: this .defs = defs;
81: }
82:
83: public String getLHSSymbolName() {
84: return (String) lhs_sym.value;
85: }
86:
87: public void accept(TreeWalker walker) {
88: walker.visit(this);
89: }
90: }
|