boost-spirit

Simple expression parser example using Boost::Spirit?

大城市里の小女人 提交于 2019-12-03 06:52:21
Is anyone aware of an online resource where I can find out how to write a simple expression parser using Boost::Spirit?. I do not necessarily need to evaluate the expression, but I need to parse it and be able to return a boolean to indicate whether the expression is parsable or not (e.g. brackets not matching etc). I need the parser to be able recognise function names (e.g. foo and foobar), so this would also be a useful example to help me learn writing BNF notation. The expressions will be normal arithmetic equations, i.e. comprising of the following symbols: opening/closing brackets

Dynamically combine Boost.Spirit.Qi rules at runtime (arbitrary number of alternatives)

ⅰ亾dé卋堺 提交于 2019-12-03 05:09:07
问题 I was wondering whether there is a way in Boost.Spirit.Qi to dynamically combine an arbitrary number of rules at runtime. The inner workings of Boost.Spirit are still a bit of a mystery to me, but since rules are implemented as objects it seems feasible. My motivation is to make certain parts of my grammar easily extendable. Consider the following contrived example: namespace qi = boost::spirit::qi; namespace px = boost::phoenix; typedef std::string::const_iterator iterator_t; template

Is it possible to re-use boost::spirit::qi grammar in another grammar definition?

大城市里の小女人 提交于 2019-12-03 04:38:18
Is it possible to reuse boost::spirit:qi grammar in another grammar (as a rule for example)? For example if I define a grammar to parse line of text into a structure holding street address. template< typename iter > struct address_grammar : qi::grammar< iter, address() > { ... qi::rule< iter, std::string() > street_name; qi::rule< iter, std::string() > street_number; qi::rule< iter, address() > address_; } I might want to reuse that grammar in two other grammars, for example one might be for parsing of a vector of addresses stored in a file. Another re-use might be in more complex structure

Parsing SQL Queries in C++ using Boost.Spirit

家住魔仙堡 提交于 2019-12-03 03:18:28
I have created a database engine in which I can create and modify tables, and add them to a database. For parsing the SQL queries, I have implemented the Boost.Spirit library using EBNF form. I have the parser setup properly and it successfully parses every rule. My problem is I now have no idea how to integrate the two. The Boost.Spirit parser only validates that input is correct, however I need it to actually do something. I looked up semantic actions but they don't seem to handle what I'm looking for. For example, if I have a query such as: new_table <- SELECT (id < 5) old_table; I want it

Minimizing boost::spirit compile times

霸气de小男生 提交于 2019-12-03 02:42:37
问题 Any ideas for reducing boost::spirit compile time? I have just ported a flex parser to boost::spirit. The EBNF has about 25 rules. The result runs well and the runtime performance is fine. The problem is that compile takes for ever! It takes about ten minutes and requires almost a gigabyte of memory. The original flex parser compiled in a few seconds. I am using boost version 1.44.0 and Visual Studio 2008. In Joel de Guzman's article 'Best Practices' it says Rules with complex definitions

Boost.Spirit.Qi: How to return attributes with Nabialek trick

隐身守侯 提交于 2019-12-03 02:30:25
Following several tutorials (e.g. http://boost-spirit.com/home/articles/qi-example/nabialek-trick/ ) I want to use the Nabialek trick to have a dynamic parser. Parsing already works fine, but I don't get the attributes transported. Explanations like https://stackoverflow.com/a/9109972/2524462 suggest, that attributes should be possible but not arguments. This is just a small example parsing a string and a number into a struct. It is just for showcasing my problem; this method should be used in a larger system later on, where the dynamic parser is really needed. Question: How do I transport

What are the disadvantages of the Spirit parser-generator framework from boost.org?

こ雲淡風輕ζ 提交于 2019-12-03 01:37:50
问题 In several questions I've seen recommendations for the Spirit parser-generator framework from boost.org, but then in the comments there is grumbling from people using Spirit who are not happy. Will those people please stand forth and explain to the rest of us what are the drawbacks or downsides to using Spirit? 回答1: It is a quite cool idea, and I liked it; it was especially useful to really learn how to use C++ templates. But their documentation recommends the usage of spirit for small to

more spirit madness - parser-types (rules vs int_parser<>) and meta-programming techniques

馋奶兔 提交于 2019-12-02 21:32:14
The question is in bold at the bottom, the problem is also summarized by the distillation code fragment towards the end. I am trying to unify my type system (the type system does to and from from type to string) into a single component(as defined by Lakos). I am using boost::array , boost::variant , and boost::mpl , in order to achieve this. I want to have the parser and generator rules for my types unified in a variant. there is a undefined type, a int4(see below) type and a int8 type. The variant reads as variant<undefined, int4,int8> . int4 traits: struct rbl_int4_parser_rule_definition {

Dynamically combine Boost.Spirit.Qi rules at runtime (arbitrary number of alternatives)

一世执手 提交于 2019-12-02 18:26:38
I was wondering whether there is a way in Boost.Spirit.Qi to dynamically combine an arbitrary number of rules at runtime. The inner workings of Boost.Spirit are still a bit of a mystery to me, but since rules are implemented as objects it seems feasible. My motivation is to make certain parts of my grammar easily extendable. Consider the following contrived example: namespace qi = boost::spirit::qi; namespace px = boost::phoenix; typedef std::string::const_iterator iterator_t; template<typename Expr> inline bool parse_full(const std::string& input, const Expr& expr) { iterator_t first(input

Minimizing boost::spirit compile times

僤鯓⒐⒋嵵緔 提交于 2019-12-02 16:17:45
Any ideas for reducing boost::spirit compile time? I have just ported a flex parser to boost::spirit. The EBNF has about 25 rules. The result runs well and the runtime performance is fine. The problem is that compile takes for ever! It takes about ten minutes and requires almost a gigabyte of memory. The original flex parser compiled in a few seconds. I am using boost version 1.44.0 and Visual Studio 2008. In Joel de Guzman's article 'Best Practices' it says Rules with complex definitions hurt the compiler badly. We’ve seen rules that are more than a hundred lines long and take a couple of