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
13 #include "../compiler2/string.hh"
14 #include "../compiler2/map.hh"
21 class Grammar : public Node {
23 SymbolMap ss; /**< every symbol */
24 map<string, Symbol> as; /**< aliases */
25 map<string, Grouping> gs; /**< groupings (every rule of the grammar) */
29 Grammar(const Grammar& p);
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);}
49 void compute_can_be_empty();
55 #endif // _langviz_Grammar_HH