Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_Parser.hpp
Go to the documentation of this file.
1 #ifndef TEUCHOS_PARSER_HPP
2 #define TEUCHOS_PARSER_HPP
3 
8 #include <Teuchos_TableDecl.hpp>
9 #include <Teuchos_Grammar.hpp>
10 
11 namespace Teuchos {
12 
13 enum ActionKind {
14  ACTION_NONE,
15  ACTION_SHIFT,
16  ACTION_REDUCE
17 };
18 
19 struct Action {
20  ActionKind kind;
21  union {
22  int production;
23  int next_state;
24  };
25 };
26 
27 #ifdef HAVE_TEUCHOSCORE_CXX11
28 extern template struct Table<Action>;
29 #endif
30 
31 struct Parser {
32  GrammarPtr grammar;
33  /* (state x terminal) -> action */
34  Table<Action> terminal_table;
35  /* (state x non-terminal) -> new state */
36  Table<int> nonterminal_table;
37  Parser() {}
38  Parser(GrammarPtr g, int nstates_reserve);
39 };
40 
41 int add_state(Parser& p);
42 int get_nstates(Parser const& p);
43 void add_terminal_action(Parser& p, int state, int terminal, Action action);
44 void add_nonterminal_action(Parser& p, int state, int nonterminal, int next_state);
45 Action const& get_action(Parser const& p, int state, int terminal);
46 int execute_action(Parser const& p, std::vector<int>& stack, Action const& action);
47 GrammarPtr const& get_grammar(Parser const& p);
48 
64 class ParserFail: public std::invalid_argument {
65  public:
66  ParserFail(const std::string& msg);
67 };
68 
94 Parser make_lalr1_parser(GrammarPtr grammar, bool verbose = false);
95 
96 }
97 
98 #endif
Parser make_lalr1_parser(GrammarPtr grammar, bool verbose)
Tries to create LALR(1) parser tables for a given grammar.
Tries to create LALR(1) parser tables for a given grammar.
Smart reference counting pointer class for automatic garbage collection.