Browse Source

Taming Boost::Spirit...

tempestpy_adaptions
dehnert 12 years ago
parent
commit
92efc9c345
  1. 96
      src/parser/PrismParser.h
  2. 17
      src/storm.cpp

96
src/parser/PrismParser.h

@ -0,0 +1,96 @@
/*
* PrismParser.h
*
* Created on: Jan 3, 2013
* Author: Christian Dehnert
*/
#ifndef PRISMPARSER_H_
#define PRISMPARSER_H_
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/io.hpp>
namespace storm {
namespace parser {
class intConstDef {
public:
std::string name;
int value;
void print() {
std::cout << "(" << name << ", " << value << ")" << std::endl;
}
};
}
}
BOOST_FUSION_ADAPT_STRUCT(
storm::parser::intConstDef,
(std::string, name)
(int, value)
)
namespace storm {
namespace parser {
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
class PrismParser {
public:
void test() {
std::string str = "const int ab = 10;";
std::string::const_iterator iter = str.begin();
std::string::const_iterator end = str.end();
prismGrammar<std::string::const_iterator> grammar;
intConstDef result;
bool r = phrase_parse(iter, end, grammar, ascii::space, result);
std::cout << r << std::endl;
if (r && iter == end) {
std::cout << "-------------------------\n";
std::cout << "Parsing succeeded\n";
result.print();
// std::cout << "result = " << result << std::endl;
std::cout << "-------------------------\n";
} else {
std::string rest(iter, end);
std::cout << "-------------------------\n";
std::cout << "Parsing failed\n";
std::cout << "stopped at: " << rest << "\"\n";
std::cout << "-------------------------\n";
}
}
private:
template<typename Iterator>
struct prismGrammar : qi::grammar<Iterator, intConstDef(), ascii::space_type> {
prismGrammar() : prismGrammar::base_type(start) {
identifierName %= +(qi::char_);
integerConstantDefinition %= qi::lit("const") >> qi::lit("int") >> identifierName >> "=" >> qi::int_ >> ";";
start %= integerConstantDefinition;
}
qi::rule<Iterator, intConstDef(), ascii::space_type> start;
qi::rule<Iterator, intConstDef(), ascii::space_type> integerConstantDefinition;
qi::rule<Iterator, std::string(), ascii::space_type> identifierName;
};
};
} // namespace parser
} // namespace storm
#endif /* PRISMPARSER_H_ */

17
src/storm.cpp

@ -35,6 +35,8 @@
#include "log4cplus/consoleappender.h"
#include "log4cplus/fileappender.h"
#include "src/parser/PrismParser.h"
#include "src/exceptions/InvalidSettingsException.h"
log4cplus::Logger logger;
@ -230,13 +232,16 @@ void testChecking() {
* Main entry point.
*/
int main(const int argc, const char* argv[]) {
initializeLogger();
if (!parseOptions(argc, argv)) {
return 0;
}
printHeader(argc, argv);
// initializeLogger();
// if (!parseOptions(argc, argv)) {
// return 0;
//}
// printHeader(argc, argv);
// testChecking();
testChecking();
storm::parser::PrismParser parser;
parser.test();
cleanUp();
return 0;

Loading…
Cancel
Save