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_MODAL_FORMULA_PARSE_H
13#define MCRL2_MODAL_FORMULA_PARSE_H
14
16#include "mcrl2/lps/parse.h"
23
24namespace mcrl2
25{
26
27namespace action_formulas
28{
29
30namespace detail {
31
32action_formula parse_action_formula(const std::string& text);
33
34} // namespace detail
35
36template <typename ActionLabelContainer = std::vector<state_formulas::variable>, typename VariableContainer = std::vector<data::variable> >
37action_formula parse_action_formula(const std::string& text,
38 const data::data_specification& dataspec,
39 const VariableContainer& variables,
40 const ActionLabelContainer& actions
41 )
42{
44 x = action_formulas::typecheck_action_formula(x, dataspec, variables, actions);
46 return x;
47}
48
49inline
51{
52 return parse_action_formula(text, lpsspec.data(), lpsspec.global_variables(), lpsspec.action_labels());
53}
54
55} // namespace action_formulas
56
57namespace regular_formulas
58{
59
60namespace detail
61{
62
63regular_formula parse_regular_formula(const std::string& text);
64
65} // namespace detail
66
67template <typename ActionLabelContainer = std::vector<state_formulas::variable>, typename VariableContainer = std::vector<data::variable> >
68regular_formula parse_regular_formula(const std::string& text,
69 const data::data_specification& dataspec,
70 const VariableContainer& variables,
71 const ActionLabelContainer& actions
72 )
73{
75 x = regular_formulas::typecheck_regular_formula(x, dataspec, variables, actions);
77 return x;
78}
79
80inline
82{
83 return parse_regular_formula(text, lpsspec.data(), lpsspec.global_variables(), lpsspec.action_labels());
84}
85
86} // namespace regular_formulas
87
88namespace state_formulas
89{
90
91namespace detail {
92
93state_formula parse_state_formula(const std::string& text);
94state_formula_specification parse_state_formula_specification(const std::string& text);
95
96} // namespace detail
97
99{
102 bool type_check = true;
105};
106
107inline
109 const state_formula& formula,
111)
112{
113 state_formula x = formula;
114 if (options.translate_regular_formulas)
115 {
116 mCRL2log(log::debug) << "formula before translating regular formulas: " << x << std::endl;
118 mCRL2log(log::debug) << "formula after translating regular formulas: " << x << std::endl;
119 }
120 if (options.translate_user_notation)
121 {
123 }
124 if (options.check_monotonicity && !is_monotonous(x))
125 {
126 throw mcrl2::runtime_error("state formula is not monotonic: " + state_formulas::pp(x));
127 }
128 if (options.resolve_name_clashes && has_state_variable_name_clashes(x))
129 {
130 mCRL2log(log::debug) << "formula before resolving name clashes: " << x << std::endl;
132 mCRL2log(log::debug) << "formula after resolving name clashes: " << x << std::endl;
133 }
134 return x;
135}
136
143inline
144state_formula parse_state_formula(const std::string& text,
146 const bool formula_is_quantitative,
148 )
149{
151 if (options.type_check)
152 {
153 x = state_formulas::typecheck_state_formula(x, lpsspec, formula_is_quantitative);
154 }
156 return post_process_state_formula(x, options);
157}
158
165inline
166state_formula parse_state_formula(const std::string& text,
167 lps::specification& lpsspec,
168 const bool formula_is_quantitative,
170 )
171{
173 state_formula phi = parse_state_formula(text, stoch_lps_spec, formula_is_quantitative, options);
174 lpsspec = remove_stochastic_operators(stoch_lps_spec);
175 return phi;
176}
177
184inline
187 const bool formula_is_quantitative,
189 )
190{
191 std::string text = utilities::read_text(in);
192 return parse_state_formula(text, lpsspec, formula_is_quantitative, options);
193}
194
201inline
203 lps::specification& lpsspec,
204 const bool formula_is_quantitative,
206 )
207{
209 state_formula phi = parse_state_formula(in, stoch_lps_spec, formula_is_quantitative, options);
210 lpsspec = remove_stochastic_operators(stoch_lps_spec);
211 return phi;
212}
213
219inline
221 const std::string& text,
222 const bool formula_is_quantitative,
224)
225{
227 if (options.type_check)
228 {
229 result.formula() = state_formulas::typecheck_state_formula(result.formula(), formula_is_quantitative, result.data(), result.action_labels(), data::variable_list());
230 }
231 result.formula() = post_process_state_formula(result.formula(), options);
232 return result;
233}
234
240inline
242 std::istream& in,
243 const bool formula_is_quantitative,
245)
246{
247 std::string text = utilities::read_text(in);
248 return parse_state_formula_specification(text, formula_is_quantitative, options);
249}
250
257inline
260 const bool formula_is_quantitative,
262 )
263{
265 // Merge data specification checks whether the combined datatypes are well typed.
268
269 if (options.type_check)
270 {
271 data::data_type_checker type_checker(dataspec);
272 // The type checker below checks whether the combined action list is well typed.
273 type_checker(result.data().user_defined_equations()); // This changes the data equations in result.data() to become well typed.
274 // Note that while type checking the formula below the non type checked equations are used. This is not an issue
275 // as the shape of equations do not influence well typedness of a modal formula.
276 result.formula() = state_formulas::typecheck_state_formula(result.formula(), formula_is_quantitative, dataspec, actspec, lpsspec.global_variables());
277 }
278
279 result.formula() = post_process_state_formula(result.formula(), options);
280 return result;
281}
282
283
290inline
292 lps::specification& lpsspec,
293 const bool formula_is_quantitative,
295 )
296{
298 state_formula_specification sfs = parse_state_formula_specification(text, stoch_lps_spec, formula_is_quantitative, options);
299 lpsspec = remove_stochastic_operators(stoch_lps_spec);
300 return sfs;
301}
302
309inline
312 const bool formula_is_quantitative,
314 )
315{
316 return parse_state_formula_specification(utilities::read_text(in), lpsspec, formula_is_quantitative, options);
317}
318
325inline
327 (std::istream& in,
328 lps::specification& lpsspec,
329 const bool formula_is_quantitative,
331 )
332{
334 state_formula_specification sfs = parse_state_formula_specification(in, stoch_lps_spec, formula_is_quantitative, options);
335 lpsspec = remove_stochastic_operators(stoch_lps_spec);
336 return sfs;
337}
338} // namespace state_formulas
339
340} // namespace mcrl2
341
342#endif // MCRL2_MODAL_FORMULA_PARSE_H
const data_equation_vector & user_defined_equations() const
Gets all user defined equations.
void add_context_sorts(const Container &c, typename atermpp::enable_if_container< Container >::type *=nullptr)
Adds the sorts in c to the context sorts.
const std::set< data::variable > & global_variables() const
Returns the declared free variables of the LPS.
const process::action_label_list & action_labels() const
Returns a sequence of action labels. This sequence contains all action labels occurring in the specif...
const data::data_specification & data() const
Returns the data specification.
Linear process specification.
Standard exception class for reporting runtime errors.
Definition exception.h:27
const state_formula & formula() const
Returns the formula of the state formula specification.
const data::data_specification & data() const
Returns the data specification.
const process::action_label_list & action_labels() const
Returns the action label specification.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:391
add your file description here.
add your file description here.
add your file description here.
add your file description here.
add your file description here.
action_formula parse_action_formula(const std::string &text)
void translate_user_notation(T &x, typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value >::type *=0)
action_formula typecheck_action_formula(const action_formula &x, const data::data_specification &dataspec, const VariableContainer &variables, const ActionLabelContainer &actions)
Definition typecheck.h:142
action_formula parse_action_formula(const std::string &text, const data::data_specification &dataspec, const VariableContainer &variables, const ActionLabelContainer &actions)
Definition parse.h:37
data_specification merge_data_specifications(const data_specification &dataspec1, const data_specification &dataspec2)
Merges two data specifications. Throws an exception if conflicts are detected.
action_label_list merge_action_specifications(const action_label_list &actspec1, const action_label_list &actspec2)
Merges two action specifications.
regular_formula parse_regular_formula(const std::string &text)
regular_formula parse_regular_formula(const std::string &text, const data::data_specification &dataspec, const VariableContainer &variables, const ActionLabelContainer &actions)
Definition parse.h:68
void translate_user_notation(T &x, typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value >::type *=0)
regular_formula typecheck_regular_formula(const regular_formula &x, const data::data_specification &dataspec, const VariableContainer &variables, const ActionLabelContainer &actions)
Definition typecheck.h:315
state_formula_specification parse_state_formula_specification(const std::string &text)
state_formula parse_state_formula(const std::string &text)
state_formula post_process_state_formula(const state_formula &formula, parse_state_formula_options options=parse_state_formula_options())
Definition parse.h:108
state_formula parse_state_formula(const std::string &text, lps::stochastic_specification &lpsspec, const bool formula_is_quantitative, parse_state_formula_options options=parse_state_formula_options())
Parses a state formula from an input stream.
Definition parse.h:144
state_formula translate_regular_formulas(const state_formula &x)
Translates regular formulas appearing in f into action formulas.
bool has_state_variable_name_clashes(const state_formula &x)
Returns true if the formula contains name clashes.
void pp(const T &t, std::ostream &out)
Prints the object t to a stream.
Definition print.h:668
void find_sort_expressions(const T &x, OutputIterator o)
Definition find.h:387
state_formulas::state_formula translate_user_notation(const state_formulas::state_formula &x)
state_formula typecheck_state_formula(const state_formula &x, const bool formula_is_quantitative, const data::data_specification &dataspec=data::data_specification(), const ActionLabelContainer &action_labels=ActionLabelContainer(), const VariableContainer &variables=VariableContainer())
Type check a state formula. Throws an exception if something went wrong.
Definition typecheck.h:784
state_formula_specification parse_state_formula_specification(const std::string &text, const bool formula_is_quantitative, parse_state_formula_options options=parse_state_formula_options())
Parses a state formula specification from a string.
Definition parse.h:220
state_formula resolve_state_variable_name_clashes(const state_formula &x)
Resolves name clashes in state variables of formula x.
bool is_monotonous(const state_formula &f, const std::set< core::identifier_string > &non_negated_variables, const std::set< core::identifier_string > &negated_variables)
Returns true if the state formula is monotonous.
std::string read_text(const std::string &filename, bool warn=false)
Read text from a file.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
Translate regular formulas in terms of state and action formulas.