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//
9/// \file mcrl2/pbes/parse.h
10/// \brief Parser for pbes expressions.
11
12#ifndef MCRL2_PBES_PARSE_H
13#define MCRL2_PBES_PARSE_H
14
15#include "mcrl2/data/detail/parse_substitution.h"
16#include "mcrl2/pbes/typecheck.h"
17#include "mcrl2/pbes/untyped_pbes.h"
18#include <boost/algorithm/string.hpp>
19#include <boost/algorithm/string/join.hpp>
20
21namespace mcrl2::pbes_system
22{
23
24namespace detail
25{
26
27pbes_expression parse_pbes_expression_new(const std::string& text);
28untyped_pbes parse_pbes_new(const std::string& text);
29void complete_pbes(pbes& x);
31pbes_expression parse_pbes_expression(const std::string& text);
32
33} // namespace detail
34
35inline
36pbes parse_pbes(std::istream& in)
37{
38 std::string text = utilities::read_text(in);
39 pbes result = detail::parse_pbes_new(text).construct_pbes();
41 return result;
42}
43
44/// \brief Reads a PBES from an input stream.
45/// \param from An input stream
46/// \param result A PBES
47/// \return The input stream
48inline
50{
51 result = parse_pbes(from);
52 return from;
53}
54
55inline
56pbes parse_pbes(const std::string& text)
57{
58 std::istringstream in(text);
59 return parse_pbes(in);
60}
61
62template <typename VariableContainer>
64 const VariableContainer& variables,
66 )
67{
68 propositional_variable result = detail::parse_propositional_variable(text);
69 return typecheck_propositional_variable(result, variables, dataspec);
70}
71
72/** \brief Parse a pbes expression.
73 * Throws an exception if something went wrong.
74 * \param[in] text A string containing a pbes expression.
75 * \param[in] variables A sequence of data variables that may appear in x.
76 * \param[in] propositional_variables A sequence of propositional variables that may appear in x.
77 * \param[in] dataspec A data specification.
78 * \param[in] type_check If true the parsed input is also typechecked.
79 * \return The parsed PBES expression.
80 **/
81template <typename VariableContainer, typename PropositionalVariableContainer>
82pbes_expression parse_pbes_expression(const std::string& text,
83 const data::data_specification& dataspec,
84 const VariableContainer& variables,
85 const PropositionalVariableContainer& propositional_variables,
86 bool type_check = true,
87 bool translate_user_notation = true,
88 bool normalize_sorts = true
89 )
90{
91 pbes_expression x = detail::parse_pbes_expression(text);
92 if (type_check)
93 {
94 x = pbes_system::typecheck_pbes_expression(x, variables, propositional_variables, dataspec);
95 }
96 if (translate_user_notation)
97 {
99 }
100 if (normalize_sorts)
101 {
102 x = pbes_system::normalize_sorts(x, dataspec);
103 }
104 return x;
105}
106
107/** \brief Parse a pbes expression.
108 * Throws an exception if something went wrong.
109 * \param[in] text A string containing a pbes expression.
110 * \param[in] pbesspec A PBES used as context.
111 * \param[in] variables A sequence of data variables that may appear in x.
112 * \param[in] type_check If true the parsed input is also typechecked.
113 * \return The parsed PBES expression.
114 **/
115template <typename VariableContainer>
117 const pbes& pbesspec,
118 const VariableContainer& variables,
119 bool type_check = true,
120 bool translate_user_notation = true,
121 bool normalize_sorts = true
122 )
123{
124 std::vector<propositional_variable> propositional_variables;
125 for (const pbes_equation& eqn: pbesspec.equations())
126 {
127 propositional_variables.push_back(eqn.variable());
128 }
129 return parse_pbes_expression(text, pbesspec.data(), variables, propositional_variables, type_check, translate_user_notation, normalize_sorts);
130}
131
132} // namespace mcrl2::pbes_system
133
134#endif // MCRL2_PBES_PARSE_H
The interface for a class that reads aterm from a stream. The default constructed term aterm() indica...
Definition aterm_io.h:62
The interface for a class that writes aterm to a stream. Every written term is retrieved by the corre...
Definition aterm_io.h:51
A helper class to restore the state of the aterm_{i,o}stream objects upon destruction....
Definition aterm_io.h:104
aterm_stream_state(aterm_stream &stream)
Definition aterm_io.h:106
A unordered_map class in which aterms can be stored.
data_specification()=default
Default constructor. Generate a data specification that contains only booleans and positive numbers.
\brief A function symbol
function_symbol(const core::identifier_string &name, const sort_expression &sort)
Constructor.
const core::identifier_string & name() const
const sort_expression & sort() const
const pbes_expression & formula() const
Returns the predicate formula on the right hand side of the equation.
pbes_equation(const fixpoint_symbol &symbol, const propositional_variable &variable, const pbes_expression &expr)
Constructor.
const fixpoint_symbol & symbol() const
Returns the fixpoint symbol of the equation.
const propositional_variable & variable() const
Returns the pbes variable of the equation.
pbes_expression & operator=(pbes_expression &&) noexcept=default
parameterized boolean equation system
Definition pbes.h:54
const propositional_variable_instantiation & initial_state() const
Returns the initial state.
Definition pbes.h:188
bool is_well_typed() const
Checks if the PBES is well typed.
Definition pbes.h:261
\brief A propositional variable instantiation
\brief A propositional variable declaration
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:393
aterm_istream & operator>>(aterm_istream &stream, aterm &term)
Read the given term from the stream, but for aterm_list we want to use a specific one that performs v...
Definition aterm_io.h:93
aterm_istream & operator>>(aterm_istream &stream, aterm_transformer transformer)
Sets the given transformer to be applied to following reads.
Definition aterm_io.h:73
atermpp::aterm_istream & operator>>(atermpp::aterm_istream &stream, data_specification &spec)
Reads a data specification from a stream.
Definition data_io.cpp:61
bool is_bes(const pbes &x)
Returns true if a PBES is in BES form.
Definition pbes.cpp:69
untyped_pbes parse_pbes_new(const std::string &text)
Definition pbes.cpp:132
void complete_pbes(pbes &x)
Definition pbes.cpp:143
pbes load_pbes(const std::string &filename)
Loads a PBES from filename, or from stdin if filename equals "".
Definition io.cpp:279
propositional_variable parse_propositional_variable(const std::string &text)
Definition pbes.cpp:150
void save_pbes(const pbes &pbesspec, const std::string &filename)
Saves an PBES to filename, or to stdout if filename equals "".
Definition io.cpp:294
pbes_expression parse_pbes_expression(const std::string &text)
Definition pbes.cpp:159
pbes_expression parse_pbes_expression_new(const std::string &text)
Definition pbes.cpp:121
The main namespace for the PBES library.
atermpp::aterm_istream & operator>>(atermpp::aterm_istream &stream, pbes &pbes)
Reads a pbes from a stream.
Definition io.cpp:234
static atermpp::aterm remove_index_impl(const atermpp::aterm &x)
Definition io.cpp:173
void load_pbes(pbes &pbes, std::istream &stream, utilities::file_format format, const std::string &)
Load a PBES from file.
Definition io.cpp:83
void save_pbes(const pbes &pbes, const std::string &filename, utilities::file_format format, bool welltypedness_check)
save_pbes Saves a PBES to a file.
Definition io.cpp:114
const utilities::file_format & pbes_format_internal_bes()
Definition io.h:43
atermpp::aterm pbes_marker()
Definition io.cpp:216
void load_pbes(pbes &pbes, const std::string &filename, utilities::file_format format)
Load pbes from file.
Definition io.cpp:149
const utilities::file_format & pbes_format_pgsolver()
Definition io.h:45
pbes parse_pbes(const std::string &text)
Definition parse.h:56
std::istream & operator>>(std::istream &from, pbes &result)
Reads a PBES from an input stream.
Definition parse.h:49
atermpp::aterm pbes_to_aterm(const pbes &p)
Conversion to atermappl.
Definition io.cpp:315
pbes parse_pbes(std::istream &in)
Definition parse.h:36
propositional_variable parse_propositional_variable(const std::string &text, const VariableContainer &variables, const data::data_specification &dataspec=data::data_specification())
Definition parse.h:63
const std::vector< utilities::file_format > & pbes_file_formats()
Definition io.cpp:27
pbes_system::pbes_expression translate_user_notation(const pbes_system::pbes_expression &x)
Definition pbes.cpp:50
void save_pbes(const pbes &pbes, std::ostream &stream, utilities::file_format format)
Save a PBES in the format specified.
Definition io.cpp:50
void complete_data_specification(pbes &)
Adds all sorts that appear in the PBES p to the data specification of p.
Definition pbes.h:308
atermpp::aterm_istream & operator>>(atermpp::aterm_istream &stream, pbes_equation &equation)
Definition io.cpp:201
const utilities::file_format & pbes_format_internal()
Definition io.h:39
const utilities::file_format & pbes_format_text()
Definition io.h:41
pbes_expression parse_pbes_expression(const std::string &text, const pbes &pbesspec, const VariableContainer &variables, bool type_check=true, bool translate_user_notation=true, bool normalize_sorts=true)
Parse a pbes expression. Throws an exception if something went wrong.
Definition parse.h:116
pbes_expression parse_pbes_expression(const std::string &text, const data::data_specification &dataspec, const VariableContainer &variables, const PropositionalVariableContainer &propositional_variables, bool type_check=true, bool translate_user_notation=true, bool normalize_sorts=true)
Parse a pbes expression. Throws an exception if something went wrong.
Definition parse.h:82
static atermpp::aterm add_index_impl(const atermpp::aterm &x)
Definition io.cpp:183