boost-spirit

boost spirit parse with the source

故事扮演 提交于 2019-12-18 08:44:12
问题 I would like to be able to parse a Number, to store its original source and to track its position in the source preserving it in the structure itself. This is what I have so far: #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_object.hpp> #include <boost/spirit/home/support/iterators/line_pos_iterator.hpp> #include

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

我的梦境 提交于 2019-12-18 08:41:06
问题 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_(); } \

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

夙愿已清 提交于 2019-12-18 08:40:03
问题 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_(); } \

How to use Boost Spirit to parse Chinese(unicode utf-16)?

让人想犯罪 __ 提交于 2019-12-18 06:59:08
问题 My program does not recognize Chinese. How to use spirit to recognize Chinese? I use wstring and has convert it to utf-16. Here is my header file: #pragma once #define BOOST_SPIRIT_UNICODE #include <boost/spirit/include/qi.hpp> #include <string> #include <vector> #include <map> using namespace std; namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; typedef pair<wstring,wstring> WordMeaningType; typedef vector<WordMeaningType> WordMeaningsType; typedef pair<wstring

How to use Boost::Spirit::Lex to lex a file without reading the whole file into memory first?

扶醉桌前 提交于 2019-12-18 06:08:11
问题 I'm looking at writing a lexer using boost::spirit::lex, but all the examples I can find seem to assume that you've read the entire file into RAM first. I'd like to write a lexer that doesn't require the whole string to be in RAM, is that possible? Or do I need to use something else? I tried using istream_iterator, but boost gives me a compile error unless I use const char* as the iterator types. e.g. All the examples I can find basically do this: lex_functor_type< lex::lexertl::lexer<> > lex

How can I use the skipper ascii::space WITHOUT skipping eol?

爱⌒轻易说出口 提交于 2019-12-17 22:37:16
问题 I have to use boost::spirit for parsing, and I want use phrase_parse function : qi::phrase_parse(str.begin(), str.end(), grammar, ascii::space - qi::eol); But the fourth term (ascii::space - qi::eol), isnt allowed by my compiler. How can I use the skipper ascii::space WITHOUT skipping eol ? 回答1: The simplest answer is qi::phrase_parse(str.begin(), str.end(), grammar, ascii::blank); Of course, it depends on your grammar too: if it expects a specific skipper class you might need to change that.

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

boost-sprit-lex unifying multiple tokens into a single token in lex differentiated by the id

霸气de小男生 提交于 2019-12-17 19:56:28
问题 edit : I have ripped out the lexer as it does not cleanly integrate with Qi and just obfuscates grammars (see answer below). My lexer looks as follows : template <typename Lexer> struct tokens : lex::lexer<Lexer> { tokens() : left_curly("\"{\""), right_curly("\"}\""), left_paren("\"(\""), right_paren("\")\""), colon(":"), scolon(";"), namespace_("(?i:namespace)"), event("(?i:event)"), optional("(?i:optional)"), required("(?i:required)"), repeated("(?i:repeated)"), t_int_4("(?i:int4)"), t_int

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