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_Grammar_HH |
14 | #define _langviz_Grammar_HH | |
15 | ||
16 | #include "Node.hh" | |
17 | #include "Symbol.hh" | |
18 | #include "../compiler2/string.hh" | |
19 | #include "../compiler2/map.hh" | |
20 | ||
21 | class Grouping; | |
22 | ||
23 | /** | |
24 | * The grammar... | |
25 | */ | |
26 | class Grammar : public Node { | |
27 | protected: | |
28 | SymbolMap ss; /**< every symbol */ | |
29 | map<string, Symbol> as; /**< aliases */ | |
30 | map<string, Grouping> gs; /**< groupings (every rule of the grammar) */ | |
31 | Symbol *startsymbol; | |
32 | int max_dist; | |
33 | ||
34 | Grammar(const Grammar& p); | |
35 | public: | |
36 | Grammar(); | |
37 | virtual ~Grammar(); | |
38 | virtual Grammar* clone() const; | |
39 | Symbol* get_symbol(const string& id); | |
40 | void add_alias(const string& s1, const string& s2); | |
41 | void add_grouping(Grouping *p_grouping); | |
42 | void set_startsymbol(Symbol *p_symbol) {startsymbol=p_symbol;} | |
43 | void set_firstsymbol(Symbol *p_symbol) | |
44 | {if(!startsymbol) startsymbol=p_symbol;} | |
45 | Symbol* get_alias(Symbol *p_symbol); | |
46 | void replace_aliases(); | |
47 | size_t get_nof_groupings() {return gs.size();} | |
48 | Grouping* get_grouping_byIndex(size_t p_i) {return gs.get_nth_elem(p_i);} | |
49 | Grouping* get_grouping_bySymbol(Symbol *p_symbol); | |
50 | size_t get_nof_symbols() {return ss.get_nof_ss();} | |
51 | Symbol* get_symbol_byIndex(size_t p_i) {return ss.get_s_byIndex(p_i);} | |
52 | protected: | |
53 | void compute_refs(); | |
54 | void compute_can_be_empty(); | |
55 | void compute_dists(); | |
56 | public: | |
57 | void compute_all(); | |
58 | }; | |
59 | ||
60 | #endif // _langviz_Grammar_HH |