mCRL2
Loading...
Searching...
No Matches
parse.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
11
12#ifndef MCRL2_PROCESS_PARSE_H
13#define MCRL2_PROCESS_PARSE_H
14
15#include "mcrl2/data/parse.h"
18
19namespace mcrl2 {
20
21namespace process {
22
23namespace detail {
24
25process_expression parse_process_expression_new(const std::string& text);
26process_specification parse_process_specification_new(const std::string& text);
27void complete_process_specification(process_specification& x, bool alpha_reduce = false);
28
29} // namespace detail
30
36process::action_label_list parse_action_declaration(const std::string& text, const data::data_specification& data_spec = data::detail::default_specification());
37
41inline
42process_specification
44{
45 std::string text = utilities::read_text(in);
48 return result;
49}
50
54inline
55process_specification
56parse_process_specification(const std::string& spec_string)
57{
58 std::istringstream in(spec_string);
60}
61
63inline
65{
66 text = utilities::trim_copy(text);
67
68 // unfortunately there is no grammar element for a process identifier, so parsing has to be done in an ad hoc manner
69 auto pos = text.find('(');
70 if (pos == std::string::npos)
71 {
73 }
74 std::string name = text.substr(0, pos);
75 std::string vardecl = utilities::trim_copy(text.substr(pos + 1));
76 vardecl.pop_back();
77
80
81 return process_identifier(id, variables);
82}
83
88inline
90 const std::string& data_decl,
91 const std::string& proc_decl
92 )
93{
94 std::string proc_text = utilities::regex_replace(";", " = delta;", proc_decl);
95 std::string init_text = "init\n " + text + ";\n";
96 std::string spec_text = data_decl + "\n" + proc_text + "\n" + init_text;
98 return spec.init();
99}
100
104inline
105process_expression parse_process_expression(const std::string& text, const std::string& procspec_text)
106{
107 std::vector<std::string> keywords{"sort", "var", "eqn", "map", "cons", "act", "glob", "proc", "init"};
108 std::pair<std::string, std::string> result = utilities::detail::separate_keyword_section(procspec_text, "init", keywords);
109 std::string init_text = "init\n " + text + ";\n";
110 std::string ptext = result.second + init_text;
112 return spec.init();
113}
114
116template <typename VariableContainer>
117process_expression parse_process_expression(const std::string& text, const VariableContainer& variables, const process_specification& procspec)
118{
119 process_specification procspec1 = procspec;
120 auto& globvars = procspec1.global_variables();
121 globvars.insert(variables.begin(), variables.end());
122 std::string ptext = process::pp(procspec1);
123 ptext = utilities::regex_replace("\\binit.*;", "init " + text + ";", ptext);
124 process_specification procspec2 =
126 return procspec2.init();
127}
128
129template <typename VariableContainer, typename ActionLabelContainer, typename ProcessIdentifierContainer>
131 const VariableContainer& variables = VariableContainer(),
133 const ActionLabelContainer& action_labels = std::vector<action_label>(),
134 const ProcessIdentifierContainer& process_identifiers = ProcessIdentifierContainer(),
135 const process_identifier* current_equation = nullptr
136 )
137{
139 x = typecheck_process_expression(x, variables, dataspec, action_labels, process_identifiers, current_equation);
141 return x;
142}
143
144} // namespace process
145
146} // namespace mcrl2
147
148#endif // MCRL2_PROCESS_PARSE_H
Term containing a string.
\brief A process expression
\brief A process identifier
Process specification consisting of a data specification, action labels, a sequence of process equati...
const process_expression & init() const
Returns the initialization of the process specification.
const std::set< data::variable > & global_variables() const
Returns the declared free variables of the process specification.
Parser for data specifications.
static data_specification const & default_specification()
Definition parse.h:31
variable_list parse_variable_declaration_list(const std::string &text, const data_specification &dataspec=detail::default_specification())
Parses a variable declaration list.
Definition parse.h:429
process_specification parse_process_specification_new(const std::string &text)
Definition process.cpp:138
void complete_process_specification(process_specification &x, bool alpha_reduce=false)
Definition process.cpp:151
process_expression parse_process_expression_new(const std::string &text)
Definition process.cpp:126
process_expression typecheck_process_expression(const process_expression &x, const VariableContainer &variables=VariableContainer(), const data::data_specification &dataspec=data::data_specification(), const ActionLabelContainer &action_labels=ActionLabelContainer(), const ProcessIdentifierContainer &process_identifiers=ProcessIdentifierContainer(), const process_identifier *current_equation=nullptr)
Typecheck a process expression.
Definition typecheck.h:702
process::action_label_list parse_action_declaration(const std::string &text, const data::data_specification &data_spec=data::detail::default_specification())
Parses an action declaration from a string.
Definition process.cpp:111
atermpp::term_list< action_label > action_label_list
\brief list of action_labels
process_expression parse_process_expression(const std::string &text, const std::string &data_decl, const std::string &proc_decl)
Parses and type checks a process expression.
Definition parse.h:89
std::string pp(const action_label &x)
Definition process.cpp:36
action translate_user_notation(const action &x)
Definition process.cpp:70
process_identifier parse_process_identifier(std::string text, const data::data_specification &dataspec)
Parses a process identifier.
Definition parse.h:64
process_specification parse_process_specification(std::istream &in)
Parses a process specification from an input stream.
Definition parse.h:43
std::pair< std::string, std::string > separate_keyword_section(const std::string &text1, const std::string &keyword, const std::vector< std::string > &all_keywords, bool repeat_keyword=false)
std::string regex_replace(const std::string &src, const std::string &dest, const std::string &text)
Regular expression replacement in a string.
std::string read_text(const std::string &filename, bool warn=false)
Read text from a file.
std::string trim_copy(const std::string &text)
Remove all trailing and leading spaces from the input.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
add your file description here.
add your file description here.