Commit | Line | Data |
---|---|---|
d44e3c4f | 1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 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 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Forstner, Matyas | |
11 | * | |
12 | ******************************************************************************/ | |
970ed795 EL |
13 | #ifndef _langviz_Rule_HH |
14 | #define _langviz_Rule_HH | |
15 | ||
16 | #include "Symbol.hh" | |
17 | #include "Node.hh" | |
18 | #include "../compiler2/string.hh" | |
19 | ||
20 | class Grammar; | |
21 | ||
22 | /** | |
23 | * Represents a rule. | |
24 | */ | |
25 | class Rule : public Node { | |
26 | protected: | |
27 | Symbols *rhs; | |
28 | ||
29 | Rule(const Rule& p); | |
30 | public: | |
31 | Rule(Symbols *p_rhs); | |
32 | virtual ~Rule(); | |
33 | virtual Rule* clone() const {return new Rule(*this);} | |
34 | size_t get_nof_ss() {return rhs->get_nof_ss();} | |
35 | Symbol* get_s_byIndex(size_t p_i) {return rhs->get_s_byIndex(p_i);} | |
36 | void replace_aliases(Grammar *grammar); | |
37 | }; | |
38 | ||
39 | /** | |
40 | * Ordered list of rules. | |
41 | */ | |
42 | class Rules : public Node { | |
43 | protected: | |
44 | vector<Rule> rs; /**< rules */ | |
45 | ||
46 | Rules(const Rules& p); | |
47 | public: | |
48 | Rules() {} | |
49 | virtual ~Rules(); | |
50 | virtual Rules* clone() const {return new Rules(*this);} | |
51 | void add_r(Rule *p_r); | |
52 | size_t get_nof_rs() const {return rs.size();} | |
53 | const Rule* get_r_byIndex(size_t p_i) const {return rs[p_i];} | |
54 | Rule*& get_r_byIndex(size_t p_i) {return rs[p_i];} | |
55 | void steal_rules(Rules *p_other); | |
56 | void replace_aliases(Grammar *grammar); | |
57 | }; | |
58 | ||
59 | /** | |
60 | * Represents a grouping (rules of a single nonterminal symbol). | |
61 | */ | |
62 | class Grouping : public Node { | |
63 | protected: | |
64 | Symbol *lhs; | |
65 | Rules *rhss; | |
66 | ||
67 | Grouping(const Grouping& p); | |
68 | public: | |
69 | Grouping(Symbol *p_lhs, Rules *p_rhss); | |
70 | virtual ~Grouping(); | |
71 | virtual Grouping* clone() const {return new Grouping(*this);} | |
72 | const string& get_id() const {return lhs->get_id();} | |
73 | void steal_rules(Grouping *p_other); | |
74 | void replace_aliases(Grammar *grammar); | |
75 | Symbol* get_lhs() {return lhs;} | |
76 | size_t get_nof_rules() const {return rhss->get_nof_rs();} | |
77 | Rule* get_rule_byIndex(size_t p_i) {return rhss->get_r_byIndex(p_i);} | |
78 | }; | |
79 | ||
80 | #endif // _langviz_Rule_HH | |
81 |