Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
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
11namespace Teuchos {
12
13enum ActionKind {
14 ACTION_NONE,
15 ACTION_SHIFT,
16 ACTION_REDUCE
17};
18
19struct Action {
20 ActionKind kind;
21 union {
22 int production;
23 int next_state;
24 };
25};
26
27#ifdef HAVE_TEUCHOSCORE_CXX11
28extern template struct Table<Action>;
29#endif
30
31struct 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
41int add_state(Parser& p);
42int get_nstates(Parser const& p);
43void add_terminal_action(Parser& p, int state, int terminal, Action action);
44void add_nonterminal_action(Parser& p, int state, int nonterminal, int next_state);
45Action const& get_action(Parser const& p, int state, int terminal);
46int execute_action(Parser const& p, std::vector<int>& stack, Action const& action);
47GrammarPtr const& get_grammar(Parser const& p);
48
64class ParserFail: public std::invalid_argument {
65 public:
66 ParserFail(const std::string& msg);
67};
68
94Parser make_lalr1_parser(GrammarPtr grammar, bool verbose = false);
95
96}
97
98#endif
Tries to create LALR(1) parser tables for a given grammar.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
Parser make_lalr1_parser(GrammarPtr grammar, bool verbose)
Tries to create LALR(1) parser tables for a given grammar.