boost-spirit

Syntax tree empty nodes issue with Spirit Qi MiniC example

耗尽温柔 提交于 2019-11-28 12:42:39
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, additive_expr, multiplicative_expr ; // expression_def.hpp expr = logical_or_expr.alias() ; logical_or

AST and operator precedence in rule definition

自作多情 提交于 2019-11-28 11:47:24
Hello [¹] I have a simple parser (see below). It intends to parse conditional expressions (relational arithmetic operations and logic combinations thereof). In the example given there, it parses successfully A>5 but then stops and ignores the rest of the input, and this is consistent with my impl. How do I change the expr_ rule to make it parse the entire input? #include <cstdint> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/variant/recursive_wrapper.hpp> namespace qi = boost::spirit::qi;

Boost Spirit parser with inherited attributes - simple example won't compile

前提是你 提交于 2019-11-28 11:25:22
问题 I'm trying to write a parser for a C-like language with boost::spirit that uses inherited attributes to transfer information about variable scope. For instance, "namespace a { var b }" would pass "a" as an attribute to the parser for "var b". I'm having trouble getting a basic parser using inherited attributes to compile this code: #ifndef CPARSER_DEF_HPP #define CPARSER_DEF_HPP #include <string> #include <boost/spirit/include/qi.hpp> namespace encoding = boost::spirit::ascii; using boost:

Factoring out common parts of Spirit rules

心不动则不痛 提交于 2019-11-28 09:50:06
问题 I have a lot of rules that have common prefix and suffix: rule = begin_stuff >> some >> other >> stuff >> end_stuff. (where begin_stuff and end_stuff are composed from literals) I wanted to be able to say rule = wrapped(some >> other >> stuff); I tried something along the lines of template<typename Rule> Rule wrapped(Rule inside) { Rule result; result = begin_stuff >> inside >> end_stuff; return result; } but all I get is lots of compile-time assertions from Qi. How can I refactor Spirit

Compilation error with a boost::spirit parser

前提是你 提交于 2019-11-28 09:23:37
问题 I have a strange problem with a calculator made using boost::spirit. This calculator is supposed to take a string as argument representing a series of arithmetical expression separated by commas, like "a+4*5,77,(b-c)*4". It also allows the string "?" and returns the array containing a -1 in this case. The calculator is initialized with a SymTable, which is a template class argument to describe any class offering the [string] -> int operator (example: a map), to resolve the value of variables.

Whitespace skipper when using Boost.Spirit Qi and Lex

我的未来我决定 提交于 2019-11-28 09:08:04
问题 Let's consider following code: #include <boost/spirit/include/lex_lexertl.hpp> #include <boost/spirit/include/qi.hpp> #include <algorithm> #include <iostream> #include <string> #include <utility> #include <vector> namespace lex = boost::spirit::lex; namespace qi = boost::spirit::qi; template<typename Lexer> class expression_lexer : public lex::lexer<Lexer> { public: typedef lex::token_def<> operator_token_type; typedef lex::token_def<> value_token_type; typedef lex::token_def<> variable_token

Boost Spirit Signals Successful Parsing Despite Token Being Incomplete

一世执手 提交于 2019-11-28 08:55:00
问题 I have a very simple path construct that I am trying to parse with boost spirit.lex. We have the following grammar: token := [a-z]+ path := (token : path) | (token) So we're just talking about colon separated lower-case ASCII strings here. I have three examples "xyz", "abc:xyz", "abc:xyz:". The first two should be deemed valid. The third one, which has a trailing colon, should not be deemed valid. Unfortunately the parser I have recognizes all three as being valid. The grammar should not

Prevent the Boost Spirit Symbol parser from accepting a keyword too early

血红的双手。 提交于 2019-11-28 08:09:07
问题 How can I prevent the Boost Spirit Symbol parser from accepting a keyword (symbol) when starts with a valid keyword (symbol). I would like the construct to fail parsing ‘ONEMORE’ as a whole and not succeed in parsing ‘ONE’ because that is a valid keyword and then fail on ‘MORE”. Here is the actual output of the code below: Keyword as a number: 1 Keyword as a number: 2 Keyword as a number: 1 Invalid keyword: MORETHREE And this is what I like it to be: Keyword as a number: 1 Keyword as a number

Slow performance using boost xpressive

夙愿已清 提交于 2019-11-28 06:52:42
问题 Lately I have being using boost xpressive for parsing files. These files are 10 MB each and there will be several hundred of them to parse. Xpressive is nice to work and clear syntax, but the problems comes with performance. It is incredible how it crawls in debug versions, while in release version it spends more than a whole second per file. I have tested against old plain get_line(), find() and sscanf() code, and it can beat xpressive easily. I understand that type checking, backtracking

Custom Skip Parser with Boost::Spirit

假装没事ソ 提交于 2019-11-28 06:27:39
The standard ascii::space_type skipper does of course not skip my comments. The docs mention you can make your own skip parser but there is no example of actually how to do it. I'd just need an example code or anything, I've been googling for 2 hours now. Please don't point me to the examples , the few links that work are hopelessly outdated, dealing with Spirit 1.6. Lanbo After some experimentation, I have found a way to specify a custom skipper and will outline it here: template<typename Iterator> struct pl0_skipper : public qi::grammar<Iterator> { pl0_skipper() : pl0_skipper::base_type(skip