From 925a9bd8c00e673cdf43e3d3082169c69471798d Mon Sep 17 00:00:00 2001 From: gereon Date: Wed, 28 Nov 2012 20:32:55 +0100 Subject: [PATCH] changing pragma to ifdef, starting implementation of PRCTLParser --- src/parser/parser.h | 16 +++++++-- src/parser/readLabFile.h | 5 ++- src/parser/readPctlFile.cpp | 32 ----------------- src/parser/readPctlFile.h | 15 -------- src/parser/readPrctlFile.cpp | 66 ++++++++++++++++++++++++++++++++++++ src/parser/readPrctlFile.h | 15 ++++++++ src/parser/readTraFile.h | 4 ++- 7 files changed, 101 insertions(+), 52 deletions(-) delete mode 100644 src/parser/readPctlFile.cpp delete mode 100644 src/parser/readPctlFile.h create mode 100644 src/parser/readPrctlFile.cpp create mode 100644 src/parser/readPrctlFile.h diff --git a/src/parser/parser.h b/src/parser/parser.h index 180b96347..f1b772040 100644 --- a/src/parser/parser.h +++ b/src/parser/parser.h @@ -5,7 +5,8 @@ * Author: Gereon Kremer */ -#pragma once +#ifndef PARSER_H_ +#define PARSER_H_ #include "src/utility/osDetection.h" @@ -66,6 +67,11 @@ namespace parser { * @brief pointer to actual file content. */ char* data; + + /*! + * @brief pointer to end of file content. + */ + char* dataend; /*! * @brief Constructor of MappedFile. @@ -102,6 +108,7 @@ namespace parser { pantheios::log_ERROR("Could not mmap ", filename, "."); throw exceptions::file_IO_exception("mrmc::parser::MappedFile Error in mmap()"); } + this->dataend = this->data + this->st.st_size; #elif defined WINDOWS #warning Windows support is implemented but has not been compiled yet... /* @@ -129,7 +136,7 @@ namespace parser { throw exceptions::file_IO_exception("mrmc::parser::MappedFile Error in CreateFileMapping()"); } - this->data = MapViewOfFile(this->mapping, FILE_MAP_READ, 0, 0, st.st_size); + this->data = MapViewOfFile(this->mapping, FILE_MAP_READ, 0, 0, this->st.st_size); if (this->data == NULL) { CloseHandle(this->mapping); @@ -137,6 +144,7 @@ namespace parser { pantheios::log_ERROR("Could not create file map view for ", filename, "."); throw exceptions::file_IO_exception("mrmc::parser::MappedFile Error in MapViewOfFile()"); } + this->dataend = this->data + this->st.st_size; #endif } @@ -158,4 +166,6 @@ namespace parser { }; } // namespace parser -} // namespace mrmc \ No newline at end of file +} // namespace mrmc + +#endif /* PARSER_H_ */ \ No newline at end of file diff --git a/src/parser/readLabFile.h b/src/parser/readLabFile.h index e948a2ce3..31375ced8 100644 --- a/src/parser/readLabFile.h +++ b/src/parser/readLabFile.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef READLABFILE_H_ +#define READLABFILE_H_ #include "src/models/atomic_propositions_labeling.h" @@ -13,3 +14,5 @@ mrmc::models::AtomicPropositionsLabeling * readLabFile(int node_count, const cha } // namespace parser } // namespace mrmc + +#endif /* READLABFILE_H_ */ \ No newline at end of file diff --git a/src/parser/readPctlFile.cpp b/src/parser/readPctlFile.cpp deleted file mode 100644 index 1c9325758..000000000 --- a/src/parser/readPctlFile.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "src/parser/readPctlFile.h" - -#include -#include -#include -#include - -namespace bs = boost::spirit; -namespace bsq = bs::qi; - -namespace -{ - using namespace bsq; - struct Parser : public bsq::grammar< char const* > - { - typedef rule< char const* > rule_t; - - rule_t atom, term, formula; - - Parser() : Parser::base_type(formula, "PCTL parser") - { - atom = double_ | (char_('(') >> formula >> char_(')') ); - term = atom >> *( char_('*') >> atom ); - formula = term >> *( char_('+') >> term ); - } - }; -} - -void readPctlFile(const char* filename) -{ - Parser p; -} \ No newline at end of file diff --git a/src/parser/readPctlFile.h b/src/parser/readPctlFile.h deleted file mode 100644 index 77e5fd3a4..000000000 --- a/src/parser/readPctlFile.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef READPCTLFILE_H_ -#define READPCTLFILE_H_ - -namespace mrmc { -namespace parser { - -/*! - * @brief Load PCTL file - */ -void readPctlFile(const char * filename); - -} // namespace parser -} // namespace mrmc - -#endif /* READPCTLFILE_H_ */ \ No newline at end of file diff --git a/src/parser/readPrctlFile.cpp b/src/parser/readPrctlFile.cpp new file mode 100644 index 000000000..0453fc15f --- /dev/null +++ b/src/parser/readPrctlFile.cpp @@ -0,0 +1,66 @@ +#include "src/parser/readPrctlFile.h" + +#include "src/parser/parser.h" + +#include + +#include +#include +#include +#include + +namespace bs = boost::spirit; + +namespace +{ + using namespace bs::qi; + using namespace bs::standard; + + struct PRCTLParser : public grammar< char const* > + { + typedef rule< char const* > rule_t; + + /*! + * @brief Generic Nonterminals. + */ + rule_t variable, value; + + /*! + * @brief Nonterminals for file header. + */ + rule_t varDef, type; + + /*! + * @brief Nonterminals for formula. + */ + rule_t formula, opP; + + /*! + * @brief Nonterminals for high-level file structure. + */ + rule_t file, header; + + PRCTLParser() : PRCTLParser::base_type(file, "PRCTL parser") + { + variable = alnum; + value = int_ | double_; + type = string("int") | string("double"); + varDef = string("const") >> type >> variable >> string("=") >> value >> string(";"); + + header = *( varDef ); + + file = header; + } + }; +} + +void readPrctlFile(const char* filename) +{ + PRCTLParser p; + mrmc::parser::MappedFile file(filename); + + if (bs::qi::parse< char const* >(file.data, file.dataend, p)) + { + std::cout << "File was parsed" << std::endl; + } +} \ No newline at end of file diff --git a/src/parser/readPrctlFile.h b/src/parser/readPrctlFile.h new file mode 100644 index 000000000..c7d508b18 --- /dev/null +++ b/src/parser/readPrctlFile.h @@ -0,0 +1,15 @@ +#ifndef READPRCTLFILE_H_ +#define READPRCTLFILE_H_ + +namespace mrmc { +namespace parser { + +/*! + * @brief Load PRCTL file + */ +void readPrctlFile(const char * filename); + +} // namespace parser +} // namespace mrmc + +#endif /* READPRCTLFILE_H_ */ \ No newline at end of file diff --git a/src/parser/readTraFile.h b/src/parser/readTraFile.h index 629acde67..2d74242a6 100644 --- a/src/parser/readTraFile.h +++ b/src/parser/readTraFile.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef READTRAFILE_H_ +#define READTRAFILE_H_ #include "src/sparse/static_sparse_matrix.h" @@ -14,3 +15,4 @@ mrmc::sparse::StaticSparseMatrix * readTraFile(const char * filename); } // namespace parser } // namespace mrmc +#endif /* READTRAFILE_H_ */ \ No newline at end of file