From 93d568bd829308c4979df765df4ceebc98bbadfb Mon Sep 17 00:00:00 2001 From: gereon Date: Sat, 1 Dec 2012 20:04:06 +0100 Subject: [PATCH] working on prctl parser --- src/parser/readPrctlFile.cpp | 81 ++++++++++++++++++++++++++++++------ src/parser/readPrctlFile.h | 4 +- 2 files changed, 72 insertions(+), 13 deletions(-) diff --git a/src/parser/readPrctlFile.cpp b/src/parser/readPrctlFile.cpp index 0453fc15f..737f6e61a 100644 --- a/src/parser/readPrctlFile.cpp +++ b/src/parser/readPrctlFile.cpp @@ -4,63 +4,120 @@ #include +#include +//#include + #include #include +#include #include +#include #include +#include + namespace bs = boost::spirit; namespace { + using namespace bs; using namespace bs::qi; using namespace bs::standard; struct PRCTLParser : public grammar< char const* > { - typedef rule< char const* > rule_t; - + typedef rule< char const* > rule_none; + typedef rule< char const*, double() > rule_double; + typedef rule< char const*, std::string() > rule_string; + /*! * @brief Generic Nonterminals. */ - rule_t variable, value; + rule_none ws; + rule_string variable; + rule_double value; /*! * @brief Nonterminals for file header. */ - rule_t varDef, type; + rule< char const* > varDef; + rule_none type; /*! * @brief Nonterminals for formula. */ - rule_t formula, opP; + rule_none formula, opP; /*! * @brief Nonterminals for high-level file structure. */ - rule_t file, header; + rule_none file, header; + + /*! + * @brief Variable assignments. + */ + std::map variables; + + /*! + * @brief Resulting formula. + */ + mrmc::formula::PCTLFormula* result; + + struct dump + { + void print(double const& i, std::string& s) + { + std::cout << s << " = " << i << std::endl; + } + void operator()(double const& a, unused_type, unused_type) const + { + std::cout << a << std::endl; + } + void operator()(std::string const& a, unused_type, unused_type) const + { + std::cout << a << std::endl; + } + void operator()(utree const& a, unused_type, unused_type) const + { + std::cout << &a << std::endl; + } + }; PRCTLParser() : PRCTLParser::base_type(file, "PRCTL parser") { - variable = alnum; - value = int_ | double_; + variable %= alnum; + ws = *( space ); + value %= ( double_ | int_ ); // double_ must be *before* int_ type = string("int") | string("double"); - varDef = string("const") >> type >> variable >> string("=") >> value >> string(";"); + varDef = + string("const") >> ws >> + type >> ws >> + variable >> ws >> + string("=") >> ws >> + value >> ws >> + string(";"); - header = *( varDef ); + header = +( varDef >> ws ); file = header; } + + }; } -void readPrctlFile(const char* filename) +mrmc::formula::PCTLFormula* mrmc::parser::readPrctlFile(const char* filename) { PRCTLParser p; mrmc::parser::MappedFile file(filename); - if (bs::qi::parse< char const* >(file.data, file.dataend, p)) + char* data = file.data; + if (bs::qi::parse< char const* >(data, file.dataend, p)) { std::cout << "File was parsed" << std::endl; + std::string rest(data, file.dataend); + std::cout << "Rest: " << rest << std::endl; + return p.result; } + else return NULL; } \ No newline at end of file diff --git a/src/parser/readPrctlFile.h b/src/parser/readPrctlFile.h index c7d508b18..c9f8ba470 100644 --- a/src/parser/readPrctlFile.h +++ b/src/parser/readPrctlFile.h @@ -1,13 +1,15 @@ #ifndef READPRCTLFILE_H_ #define READPRCTLFILE_H_ +#include "src/formula/PCTLformula.h" + namespace mrmc { namespace parser { /*! * @brief Load PRCTL file */ -void readPrctlFile(const char * filename); +mrmc::formula::PCTLFormula* readPrctlFile(const char * filename); } // namespace parser } // namespace mrmc