Merge branch 'develop'

This commit is contained in:
Oliver Kowalke 2015-01-24 23:21:30 +01:00
commit f72aae5dd6

View File

@ -5,13 +5,20 @@
// http://www.boost.org/LICENSE_1_0.txt) // http://www.boost.org/LICENSE_1_0.txt)
#include <cstdio> #include <cstdio>
#include <exception>
#include <functional> #include <functional>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <thread>
#include <boost/coroutine2/all.hpp> #include <boost/coroutine2/all.hpp>
class parser_error : public std::runtime_error {
public:
parser_error() :
std::runtime_error("parsing failed") {
}
};
/* /*
* grammar: * grammar:
* P ---> E '\0' * P ---> E '\0'
@ -77,11 +84,11 @@ private:
cb(next); cb(next);
scan(); scan();
}else{ }else{
exit(2); throw parser_error();
} }
} }
else{ else{
exit(3); throw parser_error();
} }
} }
}; };
@ -89,21 +96,30 @@ private:
typedef boost::coroutines2::asymmetric_coroutine< char > coro_t; typedef boost::coroutines2::asymmetric_coroutine< char > coro_t;
int main() { int main() {
std::istringstream is("1+1"); try {
// invert control flow std::istringstream is("1+1");
coro_t::pull_type seq( // invert control flow
boost::coroutines2::fixedsize_stack(), coro_t::pull_type seq(
[&is]( coro_t::push_type & yield) { boost::coroutines2::fixedsize_stack(),
[&is]( coro_t::push_type & yield) {
Parser p( is, Parser p( is,
[&yield](char ch){ [&yield](char ch){
yield(ch); yield(ch);
}); });
p.run(); p.run();
}); });
// user-code pulls parsed data from parser // user-code pulls parsed data from parser
for(char c:seq){ for(char c:seq){
printf("Parsed: %c\n",c); printf("Parsed: %c\n",c);
}
std::cout << "\nDone" << std::endl;
return EXIT_SUCCESS;
} catch ( std::exception const& ex) {
std::cerr << "exception: " << ex.what() << std::endl;
} }
return EXIT_FAILURE;
} }