[Boost-users] Compiler errors when using Boost::Spirit

7 views
Skip to first unread message

Evan Driscoll

unread,
Aug 7, 2012, 11:47:08 AM8/7/12
to boost...@lists.boost.org
Hey all,

I'm new to Spirit and trying to put a parser together for a very simple
language of S expressions. [Note: while I'm new to Spirit, I'm not new
to parsers or parser combinators.]

This is sort of an obnoxious email because it's basically "here, solve
my problem for me even though I haven't read the docs as well as I
could", but I figured I'd ask anyway; so if you take a look, I'm much
appreciative.


I define some tokens
template <typename Lexer>
struct tokens : lex::lexer<Lexer> {
tokens() {
this->self.add
("(", Tokens::L_Paren)
(")", Tokens::R_Paren)
("\"...\"", Tokens::String_Literal)
("[0-9]+", Tokens::Integer_Literal)
("[a-zA-Z]+", Tokens::Symbol)
;
}
};


Then a grammar:
template <typename Iterator>
struct sexp_grammar
: qi::grammar<Iterator, SExp::Ptr(), space_type>
{
qi::rule<Iterator, SExp::Ptr(), space_type> sexp;
qi::rule<Iterator, vector<SExp::Ptr>(), space_type> sexp_list;

sexp_grammar()
: sexp_grammar::base_type(sexp)
{
using qi::token;
using namespace Tokens;

sexp_list = *sexp;

sexp = token(String_Literal)
| token(Integer_Literal)
| token(Symbol)
| (token(L_Paren)
>> sexp_list
>> token(R_Paren)
);
}
};

(SExp is a class, and SExp::Ptr is a typedef to shared_ptr<SExp>.)

If I change the also tried removing the template parameters other than
Iterator in the rules, and that let it compile (albeit with a warning).


I get oodles of errors (compiling with GCC 4.6 with
g++ -o src/parser.os -c -std=c++0x -g -Wall -Wextra
-Wnon-virtual-dtor -fPIC -Iinclude src/parser.cc)
which I'm not even going to try to paste into this email and you can
look at pastebin instead:
http://pastebin.com/R5Hk9gJ0


The full code can be seen at
https://github.com/EvanED/simple_sexp/blob/master/src/parser.cc

Evan
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Evan Driscoll

unread,
Aug 7, 2012, 3:37:05 PM8/7/12
to boost...@lists.boost.org
Just FYI, I found the answer to the biggest problem in the FAQ.

Evan
Reply all
Reply to author
Forward
0 new messages