diff --git a/src/parser/PrismParser.h b/src/parser/PrismParser.h new file mode 100644 index 000000000..5b74df99a --- /dev/null +++ b/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 +#include +#include +#include +#include +#include + +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 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 + struct prismGrammar : qi::grammar { + + prismGrammar() : prismGrammar::base_type(start) { + identifierName %= +(qi::char_); + integerConstantDefinition %= qi::lit("const") >> qi::lit("int") >> identifierName >> "=" >> qi::int_ >> ";"; + + start %= integerConstantDefinition; + } + + qi::rule start; + qi::rule integerConstantDefinition; + qi::rule identifierName; + + }; +}; + +} // namespace parser + +} // namespace storm + +#endif /* PRISMPARSER_H_ */ diff --git a/src/storm.cpp b/src/storm.cpp index 0c5951961..eed86455e 100644 --- a/src/storm.cpp +++ b/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;