Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_make_lalr1_parser.hpp
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_BUILD_PARSER_HPP
11#define TEUCHOS_BUILD_PARSER_HPP
12
13#include <set>
14#include <memory>
15
16#include <Teuchos_Parser.hpp>
17#include <Teuchos_Graph.hpp>
18#include <Teuchos_RCP.hpp>
19
20namespace Teuchos {
21
22struct Config {
23 int production;
24 int dot;
25 Config(int p, int d);
26};
27
28typedef std::vector<Config> Configs;
29
30typedef std::set<int> Context;
31
32/* nonterminal transitions will be stored as SHIFT
33 actions while in progress */
34struct ActionInProgress {
35 Action action;
36 Context context;
37};
38
39struct StateInProgress {
40 std::vector<int> configs;
41 typedef std::vector<ActionInProgress> Actions;
42 Actions actions;
43};
44
45void swap(StateInProgress& a, StateInProgress& b);
46
47typedef RCP<StateInProgress> StateInProgressPtr;
48
49typedef std::vector<StateInProgressPtr> StatesInProgress;
50
51struct StateConfig {
52 int state;
53 int config_in_state;
54 StateConfig(int s, int cis);
55};
56
57typedef std::vector<StateConfig> StateConfigs;
58
59struct ParserInProgress {
60 StatesInProgress states;
61 Configs configs;
62 StateConfigs state_configs;
63 Graph states2state_configs;
64 GrammarPtr grammar;
65};
66
67StateConfigs form_state_configs(StatesInProgress const& states);
68Graph form_states_to_state_configs(StateConfigs const& scs,
69 StatesInProgress const& states);
70
71void print_graphviz(
72 std::string const& filepath,
73 ParserInProgress const& pip,
74 bool verbose,
75 std::ostream& os
76 );
77
78ParserInProgress draft_lalr1_parser(GrammarPtr grammar, bool verbose = false);
79
80Parser accept_parser(ParserInProgress const& pip);
81
82class ParserBuildFail: public std::invalid_argument {
83 public:
84 ParserBuildFail(const std::string& msg);
85};
86
87}
88
89#endif
Declares Teuchos::Parser, ParserFail and make_lalr1_parser.
Reference-counted pointer class and non-member templated function implementations.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...