Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_Parser.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef TEUCHOS_PARSER_HPP
11#define TEUCHOS_PARSER_HPP
12
17#include <Teuchos_TableDecl.hpp>
18#include <Teuchos_Grammar.hpp>
19
20namespace Teuchos {
21
22enum ActionKind {
23 ACTION_NONE,
24 ACTION_SHIFT,
25 ACTION_REDUCE
26};
27
28struct Action {
29 ActionKind kind;
30 union {
31 int production;
32 int next_state;
33 };
34};
35
36#ifdef HAVE_TEUCHOSCORE_CXX11
37extern template struct Table<Action>;
38#endif
39
40struct Parser {
41 GrammarPtr grammar;
42 /* (state x terminal) -> action */
43 Table<Action> terminal_table;
44 /* (state x non-terminal) -> new state */
45 Table<int> nonterminal_table;
46 Parser() {}
47 Parser(GrammarPtr g, int nstates_reserve);
48};
49
50int add_state(Parser& p);
51int get_nstates(Parser const& p);
52void add_terminal_action(Parser& p, int state, int terminal, Action action);
53void add_nonterminal_action(Parser& p, int state, int nonterminal, int next_state);
54Action const& get_action(Parser const& p, int state, int terminal);
55int execute_action(Parser const& p, std::vector<int>& stack, Action const& action);
56GrammarPtr const& get_grammar(Parser const& p);
57
73class ParserFail: public std::invalid_argument {
74 public:
75 ParserFail(const std::string& msg);
76};
77
103Parser make_lalr1_parser(GrammarPtr grammar, bool verbose = false);
104
105}
106
107#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.