boost-spirit-qi

How to benchmark Boost Spirit Parser?

拥有回忆 提交于 2019-11-27 21:21:12
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: copies of AST nodes, lexer, parser rules or memory. I don't think that it is I/O problem since I'm working

boost spirit qi numeric parsing of integer and floating points

こ雲淡風輕ζ 提交于 2019-11-27 18:53:31
问题 i am trying to make sense of the following result. The test case code is #include <boost/config/warning_disable.hpp> #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_fusion.hpp> #include <boost/spirit/include/phoenix_stl.hpp> #include <boost/fusion/include/adapt_struct.hpp> #include <boost/variant/recursive_variant.hpp> #include <boost/spirit/home/support/context

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

人走茶凉 提交于 2019-11-27 15:52: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 following grammar bool ok = phrase_parse(first, last, no_nan[ref(valA) = _1] >> char_('@') >> double_[ref(b)

Parse int or double using boost spirit (longest_d)

邮差的信 提交于 2019-11-27 15:09:30
I'm looking for a way to parse a string as an int or a double, the parser should try both alternatives and choose the one matching the longest portion of the input stream. There is a deprecated directive (longest_d) that does exactly what I'm looking for: number = longest_d[ integer | real ]; ...since it's deprecated, there are any other alternatives? In case it's necessary to implement a semantic action to achieve the desired behavior, does anyone have a suggestion? Firstly, do switch to Spirit V2 - which has superseded classical spirit for years now. Second, you need to make sure an int gets

How to parse reserved words correctly in boost spirit

巧了我就是萌 提交于 2019-11-27 09:43:41
I'm trying to parse a sequence of the syntax: < direction > < type > < name >. For example: in float foo where the direction can be either in , out , or in_out . I've succeeded in parsing correct text by using a qi::symbols class to convert the direction keywords to an enum. However, the problem shows when I don't have correct text. Take the example: int foo The symbol table parser will except the 'in' part of the 'int' type and so the results will be: direction: in type: t name: foo And the error is not detected. What's the best way to be able to parse the in, out and in_out reserved words

Boost spirit revert parsing

痞子三分冷 提交于 2019-11-27 08:37:22
问题 I want to parse a file containing the following structure: some garbage *&% section1 { section_content } section2 { section_content } The rule parsing section_name1 { ... } section_name2 { ... } is already defined: section_name_rule = lexeme[+char_("A-Za-z0-9_")]; section = section_name_rule > lit("{") > /*some complicated things*/... > lit("}"); sections %= +section; So I need to skip any garbage until the sections rule is met. Is there any way to accomplish this? I have tried seek[sections]

Boost spirit poor performance with Alternative parser

ぐ巨炮叔叔 提交于 2019-11-27 07:50:10
问题 I already asked question about this issue. But since there were no answers i'm asking again now with full compilable source code snippet. This code snippet should be compiled with no std=c++11 option, because of some issues with boost::variant move semantic. Just 'g++ -Wall -pedantic'. In this code snippet you will find "// Comment here" line. You can comment following block till "// And here -----". If this block is uncommented, performance of this program is very poor. So the bottleneck as

boost::spirit::qi permutation parser and synthesized attributes

不想你离开。 提交于 2019-11-27 07:21:05
问题 I'm trying to put together a simple command line parser with SPIRIT without semantic actions. I'm using BOOST 1.52 but I would like to avoid using C++11 features. The grammar has the following syntax: [-p num1] [-j] [--jobs num2] str1 str2 Optional parameters can be in any order. I successfully parsed only optional parameters. Once I add the additional mandatory two string parsers it breaks. It breaks even when I try to write down the "rstart" attributes explicitly and avoid type deduction

Syntax tree empty nodes issue with Spirit Qi MiniC example

天涯浪子 提交于 2019-11-27 07:11:35
问题 Dear Spirit Qi experts. I have played around with the MiniC example in Spirit Qi, and have noticed an issue with "empty" AST nodes in the expression grammar. It will generate "expression" nodes that hold nothing but a single operand of type "expression" again. I think the issue is due to the recursive rule definitions for the operator precedence: // expression.hpp qi::rule<Iterator, ast::expression(), skipper<Iterator> > expr, equality_expr, relational_expr, logical_or_expr, logical_and_expr,

Boost.Spirit.Qi: dynamically create “difference” parser at parse time

家住魔仙堡 提交于 2019-11-27 06:29:49
问题 A "difference" parser can be created by the binary - (minus) operator: rule = qi::char_ - qi::lit("}}") or even compound differences: rule = qi::char_ - qi::lit("}}") - qi::lit("]]") But how could I generate the whole result of the difference parser at the parse time? I'm guessing it might be some kind of form like below: phoenix::function<difference_parser_impl> difference_parser; rule = qi::lazy(difference_parser(qi::char_, {"}}", "]]"})); Here, the {..., ..., ...} part would actually be a