boost-spirit-qi

How to add qi::symbols in grammar<Iterator,double()>?

烈酒焚心 提交于 2019-12-17 20:28:57
问题 I am trying to use Boost.Spirit (V. 2.5) library to create a mini-calculator. Features I want to implement : - basic calculus (+,-,/,*), that works - some functions (like min, max), that works too - declaring/assigning double variables, and there is the problem... when I add "[vars.add]" I get compilation error (template parameter ambiguious). I've tried "add(char_(_1)", "add(_1)",... and nothing seems to work. I am obviously missing something (not understanding something actually). If

How to benchmark Boost Spirit Parser?

久未见 提交于 2019-12-17 16:06:30
问题 I'm working on a compiler and I would like to improve its performances. I found that about 50% of the time is spent parsing the source files. As the source file are quite small and I do quite a lot of transformations after that, it seems to me that it is perfectible. My parser is a Boost Spirit parser with a lexer (with lexer::pos_iterator) and I have a middle sized grammar. I'm parsing the source into an AST. My problem is that I have no idea what takes the most time during the parsing:

Constraining the existing Boost.Spirit real_parser (with a policy)

☆樱花仙子☆ 提交于 2019-12-17 14:21:26
问题 I want to parse a float, but not allow NaN values, so I generate a policy which inherits from the default policy and create a real_parser with it: // using boost::spirit::qi::{real_parser,real_policies, // phrase_parse,double_,char_}; template <typename T> struct no_nan_policy : real_policies<T> { template <typename I, typename A> static bool parse_nan(I&, I const&, A&) { return false; } }; real_parser<double, no_nan_policy<double> > no_nan; // then I can use no_nan to parse, as in the

Constraining the existing Boost.Spirit real_parser (with a policy)

笑着哭i 提交于 2019-12-17 14:21:10
问题 I want to parse a float, but not allow NaN values, so I generate a policy which inherits from the default policy and create a real_parser with it: // using boost::spirit::qi::{real_parser,real_policies, // phrase_parse,double_,char_}; template <typename T> struct no_nan_policy : real_policies<T> { template <typename I, typename A> static bool parse_nan(I&, I const&, A&) { return false; } }; real_parser<double, no_nan_policy<double> > no_nan; // then I can use no_nan to parse, as in the

Understanding Boost.spirit's string parser

拈花ヽ惹草 提交于 2019-12-17 07:50:01
问题 #include <iostream> #include <boost/spirit/include/qi.hpp> namespace qi = boost::spirit::qi; int main () { using qi::string; std::string input("a"); std::string::iterator strbegin = input.begin(); std::string p; bool ok = qi::phrase_parse(strbegin, input.end(), ((string("a") >> string("a")) | string("a")), qi::space, p); if (ok && strbegin == input.end()) { std::cout << p << std::endl; std::cout << p.size() << std::endl; } else { std::cout << "fail" << std::endl; std::cout << std::string

Assigning parsers to auto variables

[亡魂溺海] 提交于 2019-12-17 03:19:41
问题 Are spirit parsers not meant to be used with auto ? A simple parser works fine when passed to qi::parse() inline, but crashes with segfault if passed via an auto variable: #include <cstdio> #include <string> #include <boost/spirit/include/qi.hpp> using namespace std; namespace qi = boost::spirit::qi; int main() { string line = "[z]"; auto bracketed_z = '[' >> +qi::char_('z') >> ']'; auto p = line.cbegin(); printf("%d", qi::parse(p, line.cend(), '[' >> +qi::char_('z') >> ']')); // Works p =

boost spirit, boost any and quoted string - compile-time error

梦想与她 提交于 2019-12-13 18:10:01
问题 I have the following code: #include <boost/any.hpp> #include <boost/spirit/include/qi.hpp> #include <iostream> #include <string> template <typename Iterator> struct parser : boost::spirit::qi::grammar<Iterator, boost::any(), boost::spirit::qi::ascii::space_type> { parser() : parser::base_type(start) { start %= boost::spirit::qi::int_ | boost::spirit::qi::lexeme['"' >> +(boost::spirit::qi::char_ - '"') >> '"']; // example: 0 or "str" } boost::spirit::qi::rule<Iterator, boost::any(), boost:

Statefulness of Spirit V2 and X3

大城市里の小女人 提交于 2019-12-13 08:11:18
问题 What is the intent of Spirit X3 being so much 'stateless'? Bad aspects of 'states' in Spirit V2 Looking back to Spirit V2, the "grammar" was, say, conceptually stateful - in many ways. This is because the grammar was a class instance. Basically, there are lots of bad aspects for making your grammar -- or even any single rule -- to be stateful: It might make your grammar non-re-entrant; It might add thread-unsafety to your grammar instance; Self-managed 'flag' is a disaster. Theoretically

Iterative update of abstract syntax tree with boost spirit

旧时模样 提交于 2019-12-12 21:01:10
问题 I have a working boost spirit parser and was thinking if it is possible to do iterative update of an abstract syntax tree with boost spirit? I have a struct similar to: struct ast; typedef boost::variant< boost::recursive_wrapper<ast> > node; struct ast { std::vector<int> value; std::vector<node> children; }; Which is being parsed by use of: bool r = phrase_parse(begin, end, grammar, space, ast); Would it be possible to do iterative update of abstract syntax tree with boost spirit? I have not

Boost.Spirit: Setup sub-grammar during parsing

十年热恋 提交于 2019-12-12 16:56:29
问题 To handle large compile times and reuse of grammars I've composed my grammar into several sub-grammars which are called in sequence. One of them (call it: SETUP grammar) offers some configuration of the parser (via symbols parser), so later sub grammars logically depend on that one (again via different symbols parsers). So, after SETUP is parsed, the symbols parsers of the following sub grammars need to be altered. My question is, how to approach this efficiently while preserving loose