mCRL2
Loading...
Searching...
No Matches
pres.cpp
Go to the documentation of this file.
1// Author(s): Jan Friso Groote. Based on source/pbes.cpp by 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//
9/// \file pres.cpp
10/// \brief
11
12#include "mcrl2/pres/detail/has_propositional_variables.h"
13#include "mcrl2/pres/detail/instantiate_global_variables.h"
14#include "mcrl2/pres/detail/is_well_typed.h"
15#include "mcrl2/pres/detail/occurring_variable_visitor.h"
16#include "mcrl2/pres/is_res.h"
17#include "mcrl2/pres/parse_impl.h"
18#include "mcrl2/pres/print.h"
19#include "mcrl2/pres/translate_user_notation.h"
20
21namespace mcrl2
22{
23
24namespace pres_system
25{
26
27//--- start generated pres_system overloads ---//
35std::string pp(const pres_system::and_& x) { return pres_system::pp< pres_system::and_ >(x); }
36std::string pp(const pres_system::or_& x) { return pres_system::pp< pres_system::or_ >(x); }
37std::string pp(const pres_system::supremum& x) { return pres_system::pp< pres_system::supremum >(x); }
38std::string pp(const pres_system::fixpoint_symbol& x) { return pres_system::pp< pres_system::fixpoint_symbol >(x); }
39std::string pp(const pres_system::infimum& x) { return pres_system::pp< pres_system::infimum >(x); }
40std::string pp(const pres_system::sum& x) { return pres_system::pp< pres_system::sum >(x); }
41std::string pp(const pres_system::imp& x) { return pres_system::pp< pres_system::imp >(x); }
42std::string pp(const pres_system::minus& x) { return pres_system::pp< pres_system::minus >(x); }
43std::string pp(const pres_system::const_multiply& x) { return pres_system::pp< pres_system::const_multiply >(x); }
45std::string pp(const pres_system::pres& x) { return pres_system::pp< pres_system::pres >(x); }
46std::string pp(const pres_system::pres_equation& x) { return pres_system::pp< pres_system::pres_equation >(x); }
47std::string pp(const pres_system::pres_expression& x) { return pres_system::pp< pres_system::pres_expression >(x); }
48std::string pp(const pres_system::propositional_variable& x) { return pres_system::pp< pres_system::propositional_variable >(x); }
50void normalize_sorts(pres_system::pres_equation_vector& x, const data::sort_specification& sortspec) { pres_system::normalize_sorts< pres_system::pres_equation_vector >(x, sortspec); }
51void normalize_sorts(pres_system::pres& x, const data::sort_specification& /* sortspec */) { pres_system::normalize_sorts< pres_system::pres >(x, x.data()); }
52pres_system::pres_expression normalize_sorts(const pres_system::pres_expression& x, const data::sort_specification& sortspec) { return pres_system::normalize_sorts< pres_system::pres_expression >(x, sortspec); }
53void translate_user_notation(pres_system::pres& x) { pres_system::translate_user_notation< pres_system::pres >(x); }
54pres_system::pres_expression translate_user_notation(const pres_system::pres_expression& x) { return pres_system::translate_user_notation< pres_system::pres_expression >(x); }
55std::set<data::sort_expression> find_sort_expressions(const pres_system::pres& x) { return pres_system::find_sort_expressions< pres_system::pres >(x); }
56std::set<data::variable> find_all_variables(const pres_system::pres& x) { return pres_system::find_all_variables< pres_system::pres >(x); }
57std::set<data::variable> find_free_variables(const pres_system::pres& x) { return pres_system::find_free_variables< pres_system::pres >(x); }
58std::set<data::variable> find_free_variables(const pres_system::pres_expression& x) { return pres_system::find_free_variables< pres_system::pres_expression >(x); }
59std::set<data::variable> find_free_variables(const pres_system::pres_equation& x) { return pres_system::find_free_variables< pres_system::pres_equation >(x); }
60std::set<data::function_symbol> find_function_symbols(const pres_system::pres& x) { return pres_system::find_function_symbols< pres_system::pres >(x); }
61std::set<pres_system::propositional_variable_instantiation> find_propositional_variable_instantiations(const pres_system::pres_expression& x) { return pres_system::find_propositional_variable_instantiations< pres_system::pres_expression >(x); }
62std::set<core::identifier_string> find_identifiers(const pres_system::pres_expression& x) { return pres_system::find_identifiers< pres_system::pres_expression >(x); }
63bool search_variable(const pres_system::pres_expression& x, const data::variable& v) { return pres_system::search_variable< pres_system::pres_expression >(x, v); }
64//--- end generated pres_system overloads ---//
65
66namespace algorithms {
67
69{
70 pres_system::detail::instantiate_global_variables(p);
71}
72
73bool is_res(const pres& x)
74{
75 return pres_system::is_res(x);
76}
77
78} // namespace algorithms
79
81{
83}
84
86 const std::set<data::sort_expression>& declared_sorts,
87 const std::set<data::variable>& declared_global_variables,
88 const data::data_specification& data_spec
89 )
90{
91 return pres_system::detail::is_well_typed_equation(eqn, declared_sorts, declared_global_variables, data_spec);
92}
93
94bool is_well_typed_pres(const std::set<data::sort_expression>& declared_sorts,
95 const std::set<data::variable>& declared_global_variables,
96 const std::set<data::variable>& occurring_global_variables,
97 const std::set<propositional_variable>& declared_variables,
98 const std::set<propositional_variable_instantiation>& occ,
100 const data::data_specification& data_spec
101 )
102{
103 return pres_system::detail::is_well_typed_pres(declared_sorts, declared_global_variables, occurring_global_variables, declared_variables, occ, init, data_spec);
104}
105
107{
109}
110
112{
113 std::set<propositional_variable_instantiation> result;
114 for (const pres_equation& eqn: equations())
115 {
116 detail::occurring_variable_visitor f;
117 f.apply(eqn.formula());
118 result.insert(f.variables.begin(), f.variables.end());
119 }
120 return result;
121}
122
123namespace detail {
124
126{
128 unsigned int start_symbol_index = p.start_symbol_index("PresExpr");
129 bool partial_parses = false;
130 core::parse_node node = p.parse(text, start_symbol_index, partial_parses);
133 return result;
134}
135
136untyped_pres parse_pres_new(const std::string& text)
137{
139 unsigned int start_symbol_index = p.start_symbol_index("PresSpec");
140 bool partial_parses = false;
141 core::parse_node node = p.parse(text, start_symbol_index, partial_parses);
144 return result;
145}
146
148{
152}
153
154propositional_variable parse_propositional_variable(const std::string& text)
155{
157 unsigned int start_symbol_index = p.start_symbol_index("PropVarDecl");
158 bool partial_parses = false;
159 core::parse_node node = p.parse(text, start_symbol_index, partial_parses);
161}
162
164{
166 unsigned int start_symbol_index = p.start_symbol_index("PresExpr");
167 bool partial_parses = false;
168 core::parse_node node = p.parse(text, start_symbol_index, partial_parses);
171}
172
173} // namespace detail
174
175} // namespace pres_system
176
177} // namespace mcrl2
\brief A data variable
Definition variable.h:28
\brief The and operator for pres expressions
\brief The multiplication with a positive constant with the constant at the right.
\brief The multiplication with a positive constant with the constant at the left.
\brief The implication operator for pres expressions
\brief The infimum over a data type for pres expressions
\brief The not operator for pres expressions
\brief The or operator for pres expressions
bool is_solved() const
Returns true if the predicate formula on the right hand side contains no predicate variables.
Definition pres.cpp:106
const pres_expression & formula() const
Returns the predicate formula on the right hand side of the equation.
parameterized boolean equation system
Definition pres.h:59
std::set< propositional_variable_instantiation > occurring_variable_instantiations() const
Returns the set of occurring propositional variable instantiations of the pres. This is the set of va...
Definition pres.cpp:111
\brief A propositional variable instantiation
\brief The generic sum operator for pres expressions
\brief The supremeum over a data type for pres expressions
D_ParserTables parser_tables_mcrl2
Definition dparser.cpp:20
void syntax_error_fn(struct D_Parser *ap)
Custom syntax error function that prints both the line number and the column.
Definition dparser.cpp:463
D_ParseNode * ambiguity_fn(struct D_Parser *, int n, struct D_ParseNode **v)
Function for resolving parser ambiguities.
Definition dparser.cpp:332
void warn_and_or(const parse_node &)
Prints a warning for each occurrence of 'x && y || z' in the parse tree.
Namespace for all data library functionality.
Definition data.cpp:22
void instantiate_global_variables(pres &p)
Attempts to eliminate the free variables of a PRES, by substituting a constant value for them....
Definition pres.cpp:68
bool is_res(const pres &x)
Returns true if a PRES is in RES form.
Definition pres.cpp:73
void complete_pres(pres &x)
Definition pres.cpp:147
untyped_pres parse_pres_new(const std::string &text)
Definition pres.cpp:136
bool is_well_typed(const pres_equation &eqn)
Checks if the equation is well typed.
propositional_variable parse_propositional_variable(const std::string &text)
Definition pres.cpp:154
bool has_propositional_variables(const pres_expression &x)
pres_expression parse_pres_expression_new(const std::string &text)
Definition pres.cpp:125
pres_expression parse_pres_expression(const std::string &text)
Definition pres.cpp:163
The main namespace for the PRES library.
void translate_user_notation(pres_system::pres &x)
Definition pres.cpp:53
std::string pp(const pres_system::supremum &x)
Definition pres.cpp:37
std::vector< pres_expression > pres_expression_vector
\brief vector of pres_expressions
std::string pp(const pres_system::const_multiply &x)
Definition pres.cpp:43
std::set< data::variable > find_free_variables(const pres_system::pres &x)
Definition pres.cpp:57
void typecheck_pres(pres &presspec)
Type check a parsed mCRL2 pres specification. Throws an exception if something went wrong.
Definition typecheck.h:341
std::vector< propositional_variable_instantiation > propositional_variable_instantiation_vector
\brief vector of propositional_variable_instantiations
std::string pp(const pres_system::fixpoint_symbol &x)
Definition pres.cpp:38
bool is_well_typed_equation(const pres_equation &eqn, const std::set< data::sort_expression > &declared_sorts, const std::set< data::variable > &declared_global_variables, const data::data_specification &data_spec)
Definition pres.cpp:85
std::string pp(const pres_system::pres_expression &x)
Definition pres.cpp:47
std::string pp(const pres_system::infimum &x)
Definition pres.cpp:39
std::string pp(const pres_system::pres_equation &x)
Definition pres.cpp:46
void normalize_sorts(pres_system::pres_equation_vector &x, const data::sort_specification &sortspec)
Definition pres.cpp:50
std::string pp(const pres_system::propositional_variable_list &x)
Definition pres.cpp:31
bool search_variable(const pres_system::pres_expression &x, const data::variable &v)
Definition pres.cpp:63
std::string pp(const pres_system::or_ &x)
Definition pres.cpp:36
std::string pp(const pres_system::const_multiply_alt &x)
Definition pres.cpp:44
std::vector< pres_equation > pres_equation_vector
\brief vector of pres_equations
std::set< pres_system::propositional_variable_instantiation > find_propositional_variable_instantiations(const pres_system::pres_expression &x)
Definition pres.cpp:61
std::set< data::sort_expression > find_sort_expressions(const pres_system::pres &x)
Definition pres.cpp:55
std::set< data::function_symbol > find_function_symbols(const pres_system::pres &x)
Definition pres.cpp:60
void normalize_sorts(pres_system::pres &x, const data::sort_specification &)
Definition pres.cpp:51
std::set< data::variable > find_free_variables(const pres_system::pres_expression &x)
Definition pres.cpp:58
atermpp::term_list< pres_expression > pres_expression_list
\brief list of pres_expressions
std::string pp(const pres_system::pres_expression_list &x)
Definition pres.cpp:29
std::string pp(const pres_system::sum &x)
Definition pres.cpp:40
bool is_well_typed_pres(const std::set< data::sort_expression > &declared_sorts, const std::set< data::variable > &declared_global_variables, const std::set< data::variable > &occurring_global_variables, const std::set< propositional_variable > &declared_variables, const std::set< propositional_variable_instantiation > &occ, const propositional_variable_instantiation &init, const data::data_specification &data_spec)
Definition pres.cpp:94
atermpp::term_list< pbes_system::propositional_variable > propositional_variable_list
\brief list of propositional_variables
std::set< data::variable > find_free_variables(const pres_system::pres_equation &x)
Definition pres.cpp:59
std::string pp(const pres_system::pres_equation_vector &x)
Definition pres.cpp:28
std::string pp(const pres_system::and_ &x)
Definition pres.cpp:35
pres_system::pres_expression translate_user_notation(const pres_system::pres_expression &x)
Definition pres.cpp:54
std::set< core::identifier_string > find_identifiers(const pres_system::pres_expression &x)
Definition pres.cpp:62
std::string pp(const pres_system::pres &x)
Definition pres.cpp:45
std::string pp(const pres_system::imp &x)
Definition pres.cpp:41
std::vector< pbes_system::propositional_variable > propositional_variable_vector
\brief vector of propositional_variables
std::string pp(const pres_system::propositional_variable_instantiation &x)
Definition pres.cpp:49
std::string pp(const pres_system::minus &x)
Definition pres.cpp:42
pres_system::pres_expression normalize_sorts(const pres_system::pres_expression &x, const data::sort_specification &sortspec)
Definition pres.cpp:52
std::string pp(const pres_system::propositional_variable_instantiation_list &x)
Definition pres.cpp:33
void complete_data_specification(pres &)
Adds all sorts that appear in the PRES p to the data specification of p.
Definition pres.h:320
std::set< data::variable > find_all_variables(const pres_system::pres &x)
Definition pres.cpp:56
std::string pp(const pres_system::propositional_variable &x)
Definition pres.cpp:48
bool is_well_typed(const pres_equation &eqn)
Definition pres.cpp:80
atermpp::term_list< propositional_variable_instantiation > propositional_variable_instantiation_list
\brief list of propositional_variable_instantiations
Wrapper for D_ParseNode.
Definition dparser.h:86
Wrapper for D_Parser and its corresponding D_ParserTables.
Definition dparser.h:148
parse_node parse(const std::string &text, unsigned int start_symbol_index=0, bool partial_parses=false)
Parses a string. N.B. The user is responsible for destruction of the returned value by calling destro...
Definition dparser.cpp:209
parser(D_ParserTables &tables, D_AmbiguityFn ambiguity_fn=nullptr, D_SyntaxErrorFn syntax_error_fn=nullptr, std::size_t max_error_message_count=1)
Definition dparser.cpp:174
unsigned int start_symbol_index(const std::string &name) const
Definition dparser.cpp:204
pres_system::pres_expression parse_PresExpr(const core::parse_node &node) const
Definition parse_impl.h:33
pres_system::propositional_variable parse_PropVarDecl(const core::parse_node &node) const
Definition parse_impl.h:59
pres_actions(const core::parser &parser_)
Definition parse_impl.h:29
untyped_pres parse_PresSpec(const core::parse_node &node) const
Definition parse_impl.h:96
std::size_t operator()(const atermpp::detail::reference_aterm< T > &t) const