Sync with 5.4.0
[deliverable/titan.core.git] / langviz / Rule.hh
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 Ericsson Telecom AB
3 // All rights reserved. This program and the accompanying materials
4 // are made available under the terms of the Eclipse Public License v1.0
5 // which accompanies this distribution, and is available at
6 // http://www.eclipse.org/legal/epl-v10.html
7 ///////////////////////////////////////////////////////////////////////////////
8 #ifndef _langviz_Rule_HH
9 #define _langviz_Rule_HH
10
11 #include "Symbol.hh"
12 #include "Node.hh"
13 #include "../compiler2/string.hh"
14
15 class Grammar;
16
17 /**
18 * Represents a rule.
19 */
20 class Rule : public Node {
21 protected:
22 Symbols *rhs;
23
24 Rule(const Rule& p);
25 public:
26 Rule(Symbols *p_rhs);
27 virtual ~Rule();
28 virtual Rule* clone() const {return new Rule(*this);}
29 size_t get_nof_ss() {return rhs->get_nof_ss();}
30 Symbol* get_s_byIndex(size_t p_i) {return rhs->get_s_byIndex(p_i);}
31 void replace_aliases(Grammar *grammar);
32 };
33
34 /**
35 * Ordered list of rules.
36 */
37 class Rules : public Node {
38 protected:
39 vector<Rule> rs; /**< rules */
40
41 Rules(const Rules& p);
42 public:
43 Rules() {}
44 virtual ~Rules();
45 virtual Rules* clone() const {return new Rules(*this);}
46 void add_r(Rule *p_r);
47 size_t get_nof_rs() const {return rs.size();}
48 const Rule* get_r_byIndex(size_t p_i) const {return rs[p_i];}
49 Rule*& get_r_byIndex(size_t p_i) {return rs[p_i];}
50 void steal_rules(Rules *p_other);
51 void replace_aliases(Grammar *grammar);
52 };
53
54 /**
55 * Represents a grouping (rules of a single nonterminal symbol).
56 */
57 class Grouping : public Node {
58 protected:
59 Symbol *lhs;
60 Rules *rhss;
61
62 Grouping(const Grouping& p);
63 public:
64 Grouping(Symbol *p_lhs, Rules *p_rhss);
65 virtual ~Grouping();
66 virtual Grouping* clone() const {return new Grouping(*this);}
67 const string& get_id() const {return lhs->get_id();}
68 void steal_rules(Grouping *p_other);
69 void replace_aliases(Grammar *grammar);
70 Symbol* get_lhs() {return lhs;}
71 size_t get_nof_rules() const {return rhss->get_nof_rs();}
72 Rule* get_rule_byIndex(size_t p_i) {return rhss->get_r_byIndex(p_i);}
73 };
74
75 #endif // _langviz_Rule_HH
76
This page took 0.045089 seconds and 5 git commands to generate.