|
Boost Users : |
Subject: [Boost-users] Compiler errors when using Boost::Spirit
From: Evan Driscoll (driscoll_at_[hidden])
Date: 2012-08-07 11:47:08
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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net