Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_Grammar.hpp
1 #ifndef TEUCHOS_GRAMMAR_HPP
2 #define TEUCHOS_GRAMMAR_HPP
3 
4 #include <string>
5 #include <vector>
6 
7 #include <Teuchos_RCP.hpp>
8 
9 namespace Teuchos {
10 
11 /* convention: symbols are numbered with all
12  terminal symbols first, all non-terminal symbols after */
13 
14 struct Grammar {
15  typedef std::vector<int> RHS;
16  struct Production {
17  int lhs;
18  RHS rhs;
19  };
20  typedef std::vector<Production> Productions;
21  int nsymbols;
22  int nterminals;
23  Productions productions;
24  std::vector<std::string> symbol_names;
25 };
26 
27 typedef RCP<const Grammar> GrammarPtr;
28 
29 int get_nnonterminals(Grammar const& g);
30 bool is_terminal(Grammar const& g, int symbol);
31 bool is_nonterminal(Grammar const& g, int symbol);
32 int as_nonterminal(Grammar const& g, int symbol);
33 int find_goal_symbol(Grammar const& g);
34 void add_end_terminal(Grammar& g);
35 int get_end_terminal(Grammar const& g);
36 void add_accept_production(Grammar& g);
37 int get_accept_production(Grammar const& g);
38 int get_accept_nonterminal(Grammar const& g);
39 
40 std::ostream& operator<<(std::ostream& os, Grammar const& g);
41 
42 }
43 
44 #endif
Reference-counted pointer class and non-member templated function implementations.