boost-spirit

Boost spirit x3 example calculator (calc8, calc9) linker error

蹲街弑〆低调 提交于 2019-12-06 16:45:38
I'm very new with boost spirit (and with boost). Its very interesting library. I use qtcreator + MinGW 5.3. I simply add every source file from git_hub_calc8 into new project and add some boost library, but i got the following error trying to build (All other examples work fine) C:\Program Files\boost\boost\boost\spirit\home\x3\nonterminal\rule.hpp:113: ошибка: undefined reference to `bool client::parser::parse_rule<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::spirit::x3::context<boost::spirit::x3::error

Discarding parsed result after semantic action

丶灬走出姿态 提交于 2019-12-06 14:53:40
In Boost.Spirit one can read from a stream to a std::vector simply by doing: #include<vector> #include<boost/spirit/include/qi.hpp> namespace sqi = boost::spirit::qi; int main(){ std::string const v_str = "AA BB CC"; std::vector<std::string> v; auto it = begin(v_str); bool r = sqi::phrase_parse(it, end(v_str), (*sqi::lexeme[+sqi::char_("A-Z")]), sqi::space, v); assert( v.size() == 3 and v[2] == "CC" ); } However, it happens that I know the number of elements in advance because of the input format and I should be able to prereserve the space in the vector. For example if the input string is "3

How to avoid boost::phoenix when generating with boost::spirit::karma

戏子无情 提交于 2019-12-06 14:50:05
I'm a victim of error "LNK1179: invalid or corrupt file: duplicate COMDAT" and these sources lead me to believe that by not using phoenix I could avoid this error. (This is a follow-up to my previous question .) I want to replace boost::phoenix with something else. Maybe boost::bind but I don't see how I can give it access to karma::_val . The following code fails to compile on VC9 with error C2825: 'F': must be a class or namespace when followed by '::' #include <boost/config/warning_disable.hpp> #include <boost/foreach.hpp> #include <boost/assign/list_of.hpp> #include <boost/range/adaptors

Splitting string using boost spirit

柔情痞子 提交于 2019-12-06 13:41:54
问题 Is it a good idea? For a reason I thought it should be faster than boost's tokenizer or split. however most of the time I'm stuck in the boost::spirit::compile template <typename Iterator> struct ValueList : bsq::grammar<Iterator, std::vector<std::string>()> { ValueList(const std::string& sep, bool isCaseSensitive) : ValueList::base_type(query) { if(isCaseSensitive) { query = value >> *(sep >> value); value = *(bsq::char_ - sep); } else { auto separator = bsq::no_case[sep]; query = value >> *

Dynamically switching symbol tables in x3

六眼飞鱼酱① 提交于 2019-12-06 12:47:56
问题 Given the following x3 grammar that parses correctly, I want to add validation of parameters, qualifiers, and properties. This would seem to indicate some method of dynamically switching which symbol table is being used within the various rules. What is the best way to implement this? It would seem to be some mixture of semantic actions and attributes, but it is not clear to me how. #include <string> #include <vector> #include <iostream> #include <iomanip> #include <map> #include <boost

Boost Spirit Segfault In Parser

不想你离开。 提交于 2019-12-06 11:21:18
I have been trying to convert some lex and yacc code I wrote in an undergraduate compiler, course to spirit code to learn spirit and I have found a segfault that I can't seem to figure out. I wrote the lexer like this: namespace lex = boost::spirit::lex; enum Tokens { k_andTok = 1, k_def = 2, k_elihw = 3, k_elseTok = 4, k_falseTok = 5, k_fed = 6, k_fi = 7, k_ifTok = 8, k_input = 9, k_notTok = 10, k_orTok = 11, k_print = 12, k_returnTok = 13, k_trueTok = 14, k_whileTok = 15, k_plues = 16, k_minus = 17, k_mult = 18, k_div = 19, k_bang = 20, k_equalTo = 21, k_greaterEq = 22, k_lessEq = 23, k

how to get rid of escape character in a token with spirit::lex?

独自空忆成欢 提交于 2019-12-06 10:01:24
问题 I want to tokenize my own extension of SQL syntax. This involves recognizing an escaped double quote inside a double quoted string. E.g. in MySQL these two string tokens are equivalent: """" (the second double quote acts as an escape character) and '"' . I have tried different things but I am stuck at how to replace a token's value. #include <boost/spirit/include/lex_lexertl.hpp> namespace lex = boost::spirit::lex; template <typename Lexer> struct sql_tokens : lex::lexer<Lexer> { sql_tokens()

X3, how to populate a more complex AST?

喜欢而已 提交于 2019-12-06 09:27:23
Trying to generate an AST like the employee example that has more than just the employee. In my current mindset, the RExpressions example isn't helping me. The example I have doesn't compile, but I went as far as I understood in adding teams, departments, and corporations to the employee example. My problem is in understanding how to add the different structs into a variant and add the variant to phrase_parse, if that's the idea. In this example, there can be several of the same lines following each other. So wondering if that's what requires making an AST recursive. #include <boost/config

Strange semantic behaviour of boost spirit x3 after splitting

偶尔善良 提交于 2019-12-06 08:31:37
问题 I came across a strange behaviour of boost spirit x3, after I splittet my grammar up into the recommended parser.hpp , parser_def.hpp , parser.cpp files. My example gramar parses some kind of easy enums: enum = "enum" > identifier > "{" > identifier % "," > "} this is my enum grammar. When I don't split the enum and identifier parser into the recommended files, everything works fine, especially the string "enum {foo, bar}" throws an expectation failure, as expected. This example can be found

Recursive rule in Spirit.X3

允我心安 提交于 2019-12-06 08:30:17
问题 I want to parse a recursive grammar with Boost.Spirit x3, but it fails with a template instantiation depth problem. The grammar looks like : value: int | float | char | tuple int: "int: " int_ float: "float: " real_ char: "char: " char_ tuple: "tuple: [" value* "]" Here is a contained example: #include <boost/fusion/adapted.hpp> #include <boost/spirit/home/x3.hpp> #include <string> #include <vector> #include <variant> struct value: std::variant<int,float,std::vector<value>> { using std: