Compiler errors when using Boost::Spirit
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
Just FYI, I found the answer to the biggest problem in the FAQ. Evan On 08/07/2012 10:47 AM, Evan Driscoll wrote:
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
{ qi::rule sexp; qi::rule 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
participants (1)
-
Evan Driscoll