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
12 ******************************************************************************/
13 #ifndef _langviz_Grammar_HH
14 #define _langviz_Grammar_HH
18 #include "../compiler2/string.hh"
19 #include "../compiler2/map.hh"
26 class Grammar : public Node {
28 SymbolMap ss; /**< every symbol */
29 map<string, Symbol> as; /**< aliases */
30 map<string, Grouping> gs; /**< groupings (every rule of the grammar) */
34 Grammar(const Grammar& p);
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);}
54 void compute_can_be_empty();
60 #endif // _langviz_Grammar_HH