boost-spirit

Too many sections, assembler error, using boost::spirit

拟墨画扇 提交于 2019-11-29 18:14:03
问题 I'm in the progress of writing a compiler for a subset of Java, using boost::spirit , for lexing and parsing. During compilation of the lexer/parser phase, the compiler consumes 1.6GB of RAM ( g++ (GCC) 4.8.1 ), this is not an issue however, as there's plenty of memory on this machine. What is an issue however, is that when the compiler is done, and the assembler starts running ( GNU assembler (GNU Binutils) 2.23.52.20130604 ), it crashes with; as: build/src/ast_generate.o: too many sections

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

心已入冬 提交于 2019-11-29 17:30:28
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::spirit::unused_type; using boost::spirit::qi::rule; template <typename Iterator> struct cparser : boost:

boost::spirit binding function providing parameteres as spirit:qi::_val

别说谁变了你拦得住时间么 提交于 2019-11-29 17:18:18
There is a need of providing the values from an object of type boost::variant for an std::pair object. How would you implement this idea using other resources? Any other way than this is done below? struct aggr_pair_visitor : public ::boost::static_visitor<void> { public: explicit aggr_pair_visitor( column_and_aggregate & pair_ ) : pair(pair_) { } void operator()(column_name_t const & column) { pair.first = column; } void operator()(unsigned const & faggr) { if ( faggr > static_cast<unsigned>(sql_faggregate::SUM) || faggr < static_cast<unsigned>(sql_faggregate::AVG) ) throw std::runtime_error(

Stop X3 symbols from matching substrings

心已入冬 提交于 2019-11-29 16:16:25
How does one prevent X3 symbol parsers from matching partial tokens? In the example below, I want to match "foo", but not "foobar". I tried throwing the symbol parser in a lexeme directive as one would for an identifier, but then nothing matches. Thanks for any insights! #include <string> #include <iostream> #include <iomanip> #include <boost/spirit/home/x3.hpp> int main() { boost::spirit::x3::symbols<int> sym; sym.add("foo", 1); for (std::string const input : { "foo", "foobar", "barfoo" }) { using namespace boost::spirit::x3; std::cout << "\nParsing " << std::left << std::setw(20) << ("'" +

Factoring out common parts of Spirit rules

三世轮回 提交于 2019-11-29 15:59:22
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 rules in this fashion? I think you need to use the Qi Confix Parser Derective from Spirit Repository . It

Boost spirit compile issue

你。 提交于 2019-11-29 15:51:25
Hi I am very new to boost spirit library. Can you please let me know why below code is not compile? When I add "scientificNumber" rule to my grammar it dont compile. What can be the reason? I have added "scientificNumber" rule to make it possible to parse scientific notaion like "12E10". I dont know if this was the right way to do it. namespace qi = boost::spirit::qi; namespace phx = boost::phoenix; typedef boost::function<double()> Value; #define BINARY_FUNCTOR(name, op) \ struct name \ { \ name(Value x, Value y): x_(x), y_(y) {} \ double operator()() { return x_() op y_(); } \ Value x_, y_;

Compilation error with a boost::spirit parser

随声附和 提交于 2019-11-29 15:50:00
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. The following code works on my Ubuntu 10.4 with both gcc 4.6.2 and gcc 4.4, and both boost 1.47 and 1

Using boost::spirit::qi to parse numbers with separators

你说的曾经没有我的故事 提交于 2019-11-29 15:48:21
I am attempting to use boost::spirit::qi to do some parsing. It's actually going quite well, and I successfully have managed to parse numbers in various bases based on a suffix. Examples: 123, c12h, 777o, 110101b. I then wanted to add the ability to allow a completely ignored separator character, to allow values like 123_456 or 1101_0011b to parse. I tried using the skip parser, but I highly suspect that I completely misunderstood how it was to be used. It compiles just fine, but my attempt to make it ignore the underscore does absolutely nothing at all. Any suggestions on how to make this do

Boost::spirit::qi defining a calculator for nullaries

耗尽温柔 提交于 2019-11-29 15:14:19
I'm trying to write a parser for math expressions where named variables are nullaries in boost::spirit (version 1_51_0), to which I'm completely new. I define typedef boost::function<double()> Value and my rules will be declared like so: qi::rule<Iterator, Value()> expression, term, others, ...; I define binary operators on nullaries with this macro #define BINARY_FUNCTOR(name, op) \ struct name \ { \ name(Value x, Value y): x_(x), y_(y) {} \ double operator()() { return x_() op y_(); } \ Value x_, y_; \ }; and have ADD , SUB , etc. From the examples I've seen, I'd expect the rules to be

How to print the variables matched by the symbol table in Boost spirit parser?

馋奶兔 提交于 2019-11-29 15:14:11
问题 I am a beginner in using boost spirit Say that I have the following code that parse a simple arithmetic expression with variables: #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/variant/recursive_variant.hpp> #include <boost/variant/apply_visitor.hpp> #include <boost/fusion/include/adapt_struct.hpp> #include <boost/spirit/include/phoenix_function.hpp> #include <boost/foreach.hpp> #include <iostream> #include <string> namespace client {