|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r69024 - trunk/libs/spirit/example/qi
From: joel_at_[hidden]
Date: 2011-02-19 04:22:33
Author: djowel
Date: 2011-02-19 04:22:28 EST (Sat, 19 Feb 2011)
New Revision: 69024
URL: http://svn.boost.org/trac/boost/changeset/69024
Log:
Tweaks. Allow attribute compatibility on alternatives
Text files modified:
trunk/libs/spirit/example/qi/calc2_ast2.cpp | 34 +++++++++++++++++-----------------
1 files changed, 17 insertions(+), 17 deletions(-)
Modified: trunk/libs/spirit/example/qi/calc2_ast2.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc2_ast2.cpp (original)
+++ trunk/libs/spirit/example/qi/calc2_ast2.cpp 2011-02-19 04:22:28 EST (Sat, 19 Feb 2011)
@@ -8,7 +8,7 @@
//
// A Calculator example demonstrating generation of AST
//
-// [ JDG April 28, 2008 ]
+// [ JDG April 28, 2008 : For BoostCon 2008 ]
// [ JDG February 18, 2011 : Pure attributes. No semantic actions. ]
//
///////////////////////////////////////////////////////////////////////////////
@@ -30,7 +30,7 @@
{
struct nil {};
struct signed_;
- struct program;
+ struct operation;
typedef boost::variant<
nil
@@ -126,15 +126,15 @@
int operator()(nil) const { BOOST_ASSERT(0); return 0; }
int operator()(unsigned int n) const { return n; }
- int operator()(operation const& x, int state) const
+ int operator()(operation const& x, int lhs) const
{
int rhs = boost::apply_visitor(*this, x.operand_);
switch (x.operator_)
{
- case '+': return state + rhs;
- case '-': return state - rhs;
- case '*': return state * rhs;
- case '/': return state / rhs;
+ case '+': return lhs + rhs;
+ case '-': return lhs - rhs;
+ case '*': return lhs * rhs;
+ case '/': return lhs / rhs;
}
BOOST_ASSERT(0);
return 0;
@@ -195,7 +195,7 @@
;
factor =
- uint_
+ uint_
| '(' >> expression >> ')'
| (char_('-') >> factor)
| (char_('+') >> factor)
@@ -219,10 +219,9 @@
std::cout << "/////////////////////////////////////////////////////////\n\n";
std::cout << "Type an expression...or [q or Q] to quit\n\n";
- boost::spirit::ascii::space_type space;
typedef std::string::const_iterator iterator_type;
typedef client::calculator<iterator_type> calculator;
- typedef client::ast::program program;
+ typedef client::ast::program ast_program;
typedef client::ast::printer ast_print;
typedef client::ast::eval ast_eval;
@@ -232,21 +231,22 @@
if (str.empty() || str[0] == 'q' || str[0] == 'Q')
break;
- calculator calc; // Our grammar
- program ast; // Our AST
- ast_print printer; // Prints the AST
- ast_eval eval; // Evaluates the AST
+ calculator calc; // Our grammar
+ ast_program program; // Our program (AST)
+ ast_print printer; // Prints the program
+ ast_eval eval; // Evaluates the program
std::string::const_iterator iter = str.begin();
std::string::const_iterator end = str.end();
- bool r = phrase_parse(iter, end, calc, space, ast);
+ boost::spirit::ascii::space_type space;
+ bool r = phrase_parse(iter, end, calc, space, program);
if (r && iter == end)
{
std::cout << "-------------------------\n";
std::cout << "Parsing succeeded\n";
- printer(ast);
- std::cout << "\nResult: " << eval(ast) << std::endl;
+ printer(program);
+ std::cout << "\nResult: " << eval(program) << std::endl;
std::cout << "-------------------------\n";
}
else
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk