ee8a2ba74c02385ffe8115d24c29b79e2e01fd76
[deliverable/titan.core.git] / langviz / Grammar.hh
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 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_Grammar_HH
9 #define _langviz_Grammar_HH
10
11 #include "Node.hh"
12 #include "Symbol.hh"
13 #include "../compiler2/string.hh"
14 #include "../compiler2/map.hh"
15
16 class Grouping;
17
18 /**
19 * The grammar...
20 */
21 class Grammar : public Node {
22 protected:
23 SymbolMap ss; /**< every symbol */
24 map<string, Symbol> as; /**< aliases */
25 map<string, Grouping> gs; /**< groupings (every rule of the grammar) */
26 Symbol *startsymbol;
27 int max_dist;
28
29 Grammar(const Grammar& p);
30 public:
31 Grammar();
32 virtual ~Grammar();
33 virtual Grammar* clone() const;
34 Symbol* get_symbol(const string& id);
35 void add_alias(const string& s1, const string& s2);
36 void add_grouping(Grouping *p_grouping);
37 void set_startsymbol(Symbol *p_symbol) {startsymbol=p_symbol;}
38 void set_firstsymbol(Symbol *p_symbol)
39 {if(!startsymbol) startsymbol=p_symbol;}
40 Symbol* get_alias(Symbol *p_symbol);
41 void replace_aliases();
42 size_t get_nof_groupings() {return gs.size();}
43 Grouping* get_grouping_byIndex(size_t p_i) {return gs.get_nth_elem(p_i);}
44 Grouping* get_grouping_bySymbol(Symbol *p_symbol);
45 size_t get_nof_symbols() {return ss.get_nof_ss();}
46 Symbol* get_symbol_byIndex(size_t p_i) {return ss.get_s_byIndex(p_i);}
47 protected:
48 void compute_refs();
49 void compute_can_be_empty();
50 void compute_dists();
51 public:
52 void compute_all();
53 };
54
55 #endif // _langviz_Grammar_HH
This page took 0.062944 seconds and 5 git commands to generate.