|
Boost : |
From: Michael Burbidge (mburbidg_at_[hidden])
Date: 2003-09-06 20:15:21
The following is a simple program that uses spirit to parse a trivial
grammar. Of course my real grammar is not so simple, but I've narrowed
it down to a very small example. When I run the program it crashes
during the call to parse. I've tried this program on Windows and
Macintosh and using the spirit in boost 1.30.2 and the latest spirit
1.7.0. They all crash. This code was derived from the ast calc example.
If I change the line:
rule<ScannerT, parser_context, parser_tag<escaped_expr_id> >
escaped_expr;
to:
rule<ScannerT > escaped_expr;
it doesn't crash. But since I'm trying to build a abstract syntax tree
I really need the rule id. Can anyone tell me how I might change my
simple program so that it doesn't crash?
Thanks,
Michael-
//------------------------------------------------------------------
#include "boost/spirit/core.hpp"
using namespace boost::spirit;
#include <iostream>
#include <string>
using namespace std;
struct expr_grammar : public grammar<expr_grammar>
{
static const int escaped_expr_id = 1;
template <typename ScannerT>
struct definition
{
definition(expr_grammar const& self)
{
escaped_expr
= ch_p('{') >> ch_p('}')
;
}
rule<ScannerT, parser_context, parser_tag<escaped_expr_id>
> escaped_expr;
rule<ScannerT> const& start() const { return escaped_expr; }
};
};
int main()
{
cout << "Type an expression...or [q or Q] to quit\n\n";
expr_grammar g;
string str;
while (getline(cin, str))
{
if (str[0] == 'q' || str[0] == 'Q')
break;
parse_info<> info = parse(str.c_str(), g, space_p);
if (info.full)
cout << "Parsing succeeded\n";
else
cout << "Parsing failed\n";
}
return 0;
}
//--------------------------------------
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk