Browse Source

changing pragma to ifdef, starting implementation of PRCTLParser

tempestpy_adaptions
gereon 12 years ago
parent
commit
925a9bd8c0
  1. 16
      src/parser/parser.h
  2. 5
      src/parser/readLabFile.h
  3. 32
      src/parser/readPctlFile.cpp
  4. 15
      src/parser/readPctlFile.h
  5. 66
      src/parser/readPrctlFile.cpp
  6. 15
      src/parser/readPrctlFile.h
  7. 4
      src/parser/readTraFile.h

16
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
} // namespace mrmc
#endif /* PARSER_H_ */

5
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_ */

32
src/parser/readPctlFile.cpp

@ -1,32 +0,0 @@
#include "src/parser/readPctlFile.h"
#include <boost/spirit/include/classic_core.hpp>
#include <boost/spirit/include/qi_grammar.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/qi_char_class.hpp>
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;
}

15
src/parser/readPctlFile.h

@ -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_ */

66
src/parser/readPrctlFile.cpp

@ -0,0 +1,66 @@
#include "src/parser/readPrctlFile.h"
#include "src/parser/parser.h"
#include <iostream>
#include <boost/spirit/include/classic_core.hpp>
#include <boost/spirit/include/qi_grammar.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/qi_char_class.hpp>
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;
}
}

15
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_ */

4
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<double> * readTraFile(const char * filename);
} // namespace parser
} // namespace mrmc
#endif /* READTRAFILE_H_ */
Loading…
Cancel
Save