Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69675 - in trunk/libs/spirit/example/qi: . calc6 calc7 mini_c
From: joel_at_[hidden]
Date: 2011-03-07 21:36:51


Author: djowel
Date: 2011-03-07 21:36:48 EST (Mon, 07 Mar 2011)
New Revision: 69675
URL: http://svn.boost.org/trac/boost/changeset/69675

Log:
Removing old calculators
Removed:
   trunk/libs/spirit/example/qi/calc1.cpp
   trunk/libs/spirit/example/qi/calc2.cpp
   trunk/libs/spirit/example/qi/calc2_ast.cpp
   trunk/libs/spirit/example/qi/calc2_ast2.cpp
   trunk/libs/spirit/example/qi/calc3.cpp
   trunk/libs/spirit/example/qi/calc4.cpp
   trunk/libs/spirit/example/qi/calc4_debug.cpp
   trunk/libs/spirit/example/qi/calc5.cpp
   trunk/libs/spirit/example/qi/calc6/
   trunk/libs/spirit/example/qi/calc7/
   trunk/libs/spirit/example/qi/mini_c/
Text files modified:
   trunk/libs/spirit/example/qi/Jamfile | 33 +--------------------------------
   1 files changed, 1 insertions(+), 32 deletions(-)

Modified: trunk/libs/spirit/example/qi/Jamfile
==============================================================================
--- trunk/libs/spirit/example/qi/Jamfile (original)
+++ trunk/libs/spirit/example/qi/Jamfile 2011-03-07 21:36:48 EST (Mon, 07 Mar 2011)
@@ -5,7 +5,7 @@
 # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 #==============================================================================
 project spirit-qi-example
- : requirements
+ : requirements
         <toolset>gcc:<c++-template-depth>300
         <toolset>darwin:<cxxflags>-ftemplate-depth-300
     :
@@ -39,41 +39,10 @@
 
 exe unescaped_string : unescaped_string.cpp ;
 
-exe calculator1 : calc1.cpp ;
-exe calculator2 : calc2.cpp ;
-exe calculator2_ast : calc2_ast.cpp ;
-exe calculator3 : calc3.cpp ;
-#exe calc3_lexer : calc3_lexer.cpp ;
-exe calculator4 : calc4.cpp ;
-exe calculator4_debug : calc4_debug.cpp ;
-exe calculator5 : calc5.cpp ;
-
-exe calculator6 :
- calc6/calc6.cpp
- calc6/calc6a.cpp
- calc6/calc6b.cpp
- calc6/calc6c.cpp
- ;
-
-exe calculator7 :
- calc7/calc7.cpp
- calc7/calc7a.cpp
- calc7/calc7b.cpp
- calc7/calc7c.cpp
- ;
-
 exe calc_utree_naive : calc_utree_naive.cpp ;
 exe calc_utree_ast : calc_utree_ast.cpp ;
 exe calc_utree : calc_utree.cpp ;
 
-exe mini_c_interp :
- mini_c/mini_c.cpp
- mini_c/mini_ca.cpp
- mini_c/mini_cb.cpp
- mini_c/mini_cc.cpp
- mini_c/mini_cd.cpp
- ;
-
 exe nabialek : nabialek.cpp ;
 exe typeof : typeof.cpp ;
 

Deleted: trunk/libs/spirit/example/qi/calc1.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc1.cpp 2011-03-07 21:36:48 EST (Mon, 07 Mar 2011)
+++ (empty file)
@@ -1,112 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-///////////////////////////////////////////////////////////////////////////////
-//
-// Plain calculator example demonstrating the grammar. The parser is a
-// syntax checker only and does not do any semantic evaluation.
-//
-// [ JDG May 10, 2002 ] spirit1
-// [ JDG March 4, 2007 ] spirit2
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
-
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <iostream>
-#include <string>
-
-namespace client
-{
- namespace qi = boost::spirit::qi;
- namespace ascii = boost::spirit::ascii;
-
- ///////////////////////////////////////////////////////////////////////////////
- // Our calculator grammar
- ///////////////////////////////////////////////////////////////////////////////
- template <typename Iterator>
- struct calculator : qi::grammar<Iterator, ascii::space_type>
- {
- calculator() : calculator::base_type(expression)
- {
- qi::uint_type uint_;
-
- expression =
- term
- >> *( ('+' >> term)
- | ('-' >> term)
- )
- ;
-
- term =
- factor
- >> *( ('*' >> factor)
- | ('/' >> factor)
- )
- ;
-
- factor =
- uint_
- | '(' >> expression >> ')'
- | ('-' >> factor)
- | ('+' >> factor)
- ;
- }
-
- qi::rule<Iterator, ascii::space_type> expression, term, factor;
- };
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Expression parser...\n\n";
- 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;
-
- calculator calc; // Our grammar
-
- std::string str;
- while (std::getline(std::cin, str))
- {
- if (str.empty() || str[0] == 'q' || str[0] == 'Q')
- break;
-
- std::string::const_iterator iter = str.begin();
- std::string::const_iterator end = str.end();
- bool r = phrase_parse(iter, end, calc, space);
-
- if (r && iter == end)
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing succeeded\n";
- std::cout << "-------------------------\n";
- }
- else
- {
- std::string rest(iter, end);
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "stopped at: \": " << rest << "\"\n";
- std::cout << "-------------------------\n";
- }
- }
-
- std::cout << "Bye... :-) \n\n";
- return 0;
-}
-
-

Deleted: trunk/libs/spirit/example/qi/calc2.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc2.cpp 2011-03-07 21:36:48 EST (Mon, 07 Mar 2011)
+++ (empty file)
@@ -1,125 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-///////////////////////////////////////////////////////////////////////////////
-//
-// A Calculator example demonstrating the grammar and semantic actions
-// using plain functions. The parser prints code suitable for a stack
-// based virtual machine.
-//
-// [ JDG May 10, 2002 ] spirit1
-// [ JDG March 4, 2007 ] spirit2
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/qi.hpp>
-
-#include <iostream>
-#include <string>
-
-namespace client
-{
- namespace qi = boost::spirit::qi;
- namespace ascii = boost::spirit::ascii;
-
- ///////////////////////////////////////////////////////////////////////////////
- // Semantic actions
- ////////////////////////////////////////////////////////1///////////////////////
- namespace
- {
- void do_int(int n) { std::cout << "push " << n << std::endl; }
- void do_add() { std::cout << "add\n"; }
- void do_subt() { std::cout << "subtract\n"; }
- void do_mult() { std::cout << "mult\n"; }
- void do_div() { std::cout << "divide\n"; }
- void do_neg() { std::cout << "negate\n"; }
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // Our calculator grammar
- ///////////////////////////////////////////////////////////////////////////////
- template <typename Iterator>
- struct calculator : qi::grammar<Iterator, ascii::space_type>
- {
- calculator() : calculator::base_type(expression)
- {
- using qi::uint_;
-
- expression =
- term
- >> *( ('+' >> term [&do_add])
- | ('-' >> term [&do_subt])
- )
- ;
-
- term =
- factor
- >> *( ('*' >> factor [&do_mult])
- | ('/' >> factor [&do_div])
- )
- ;
-
- factor =
- uint_ [&do_int]
- | '(' >> expression >> ')'
- | ('-' >> factor [&do_neg])
- | ('+' >> factor)
- ;
- }
-
- qi::rule<Iterator, ascii::space_type> expression, term, factor;
- };
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Expression parser...\n\n";
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Type an expression...or [q or Q] to quit\n\n";
-
- using boost::spirit::ascii::space;
- typedef std::string::const_iterator iterator_type;
- typedef client::calculator<iterator_type> calculator;
-
- calculator calc; // Our grammar
-
- std::string str;
- while (std::getline(std::cin, str))
- {
- if (str.empty() || str[0] == 'q' || str[0] == 'Q')
- break;
-
- std::string::const_iterator iter = str.begin();
- std::string::const_iterator end = str.end();
- bool r = phrase_parse(iter, end, calc, space);
-
- if (r && iter == end)
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing succeeded\n";
- std::cout << "-------------------------\n";
- }
- else
- {
- std::string rest(iter, end);
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "stopped at: \": " << rest << "\"\n";
- std::cout << "-------------------------\n";
- }
- }
-
- std::cout << "Bye... :-) \n\n";
- return 0;
-}
-
-

Deleted: trunk/libs/spirit/example/qi/calc2_ast.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc2_ast.cpp 2011-03-07 21:36:48 EST (Mon, 07 Mar 2011)
+++ (empty file)
@@ -1,254 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-///////////////////////////////////////////////////////////////////////////////
-//
-// A Calculator example demonstrating generation of AST
-//
-// [ JDG April 28, 2008 ]
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/variant/recursive_variant.hpp>
-#include <boost/variant/apply_visitor.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-#include <boost/spirit/include/phoenix_function.hpp>
-
-#include <iostream>
-#include <vector>
-#include <string>
-
-namespace client
-{
- namespace qi = boost::spirit::qi;
- namespace ascii = boost::spirit::ascii;
-
- ///////////////////////////////////////////////////////////////////////////
- // Our AST
- ///////////////////////////////////////////////////////////////////////////
- struct binary_op;
- struct unary_op;
- struct nil {};
-
- struct expression_ast
- {
- typedef
- boost::variant<
- nil // can't happen!
- , unsigned int
- , boost::recursive_wrapper<expression_ast>
- , boost::recursive_wrapper<binary_op>
- , boost::recursive_wrapper<unary_op>
- >
- type;
-
- expression_ast()
- : expr(nil()) {}
-
- template <typename Expr>
- expression_ast(Expr const& expr)
- : expr(expr) {}
-
- expression_ast& operator+=(expression_ast const& rhs);
- expression_ast& operator-=(expression_ast const& rhs);
- expression_ast& operator*=(expression_ast const& rhs);
- expression_ast& operator/=(expression_ast const& rhs);
-
- type expr;
- };
-
- struct binary_op
- {
- binary_op(
- char op
- , expression_ast const& left
- , expression_ast const& right)
- : op(op), left(left), right(right) {}
-
- char op;
- expression_ast left;
- expression_ast right;
- };
-
- struct unary_op
- {
- unary_op(
- char op
- , expression_ast const& subject)
- : op(op), subject(subject) {}
-
- char op;
- expression_ast subject;
- };
-
- expression_ast& expression_ast::operator+=(expression_ast const& rhs)
- {
- expr = binary_op('+', expr, rhs);
- return *this;
- }
-
- expression_ast& expression_ast::operator-=(expression_ast const& rhs)
- {
- expr = binary_op('-', expr, rhs);
- return *this;
- }
-
- expression_ast& expression_ast::operator*=(expression_ast const& rhs)
- {
- expr = binary_op('*', expr, rhs);
- return *this;
- }
-
- expression_ast& expression_ast::operator/=(expression_ast const& rhs)
- {
- expr = binary_op('/', expr, rhs);
- return *this;
- }
-
- // We should be using expression_ast::operator-. There's a bug
- // in phoenix type deduction mechanism that prevents us from
- // doing so. Phoenix will be switching to BOOST_TYPEOF. In the
- // meantime, we will use a phoenix::function below:
- struct negate_expr
- {
- template <typename T>
- struct result { typedef T type; };
-
- expression_ast operator()(expression_ast const& expr) const
- {
- return expression_ast(unary_op('-', expr));
- }
- };
-
- boost::phoenix::function<negate_expr> neg;
-
- ///////////////////////////////////////////////////////////////////////////
- // Walk the tree
- ///////////////////////////////////////////////////////////////////////////
- struct ast_print
- {
- typedef void result_type;
-
- void operator()(qi::info::nil) const {}
- void operator()(int n) const { std::cout << n; }
-
- void operator()(expression_ast const& ast) const
- {
- boost::apply_visitor(*this, ast.expr);
- }
-
- void operator()(binary_op const& expr) const
- {
- std::cout << "op:" << expr.op << "(";
- boost::apply_visitor(*this, expr.left.expr);
- std::cout << ", ";
- boost::apply_visitor(*this, expr.right.expr);
- std::cout << ')';
- }
-
- void operator()(unary_op const& expr) const
- {
- std::cout << "op:" << expr.op << "(";
- boost::apply_visitor(*this, expr.subject.expr);
- std::cout << ')';
- }
- };
-
- ///////////////////////////////////////////////////////////////////////////
- // Our calculator grammar
- ///////////////////////////////////////////////////////////////////////////
- template <typename Iterator>
- struct calculator : qi::grammar<Iterator, expression_ast(), ascii::space_type>
- {
- calculator() : calculator::base_type(expression)
- {
- using qi::_val;
- using qi::_1;
- using qi::uint_;
-
- expression =
- term [_val = _1]
- >> *( ('+' >> term [_val += _1])
- | ('-' >> term [_val -= _1])
- )
- ;
-
- term =
- factor [_val = _1]
- >> *( ('*' >> factor [_val *= _1])
- | ('/' >> factor [_val /= _1])
- )
- ;
-
- factor =
- uint_ [_val = _1]
- | '(' >> expression [_val = _1] >> ')'
- | ('-' >> factor [_val = neg(_1)])
- | ('+' >> factor [_val = _1])
- ;
- }
-
- qi::rule<Iterator, expression_ast(), ascii::space_type>
- expression, term, factor;
- };
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Expression parser...\n\n";
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Type an expression...or [q or Q] to quit\n\n";
-
- using boost::spirit::ascii::space;
- using client::expression_ast;
- using client::ast_print;
-
- typedef std::string::const_iterator iterator_type;
- typedef client::calculator<iterator_type> calculator;
-
- calculator calc; // Our grammar
-
- std::string str;
- while (std::getline(std::cin, str))
- {
- if (str.empty() || str[0] == 'q' || str[0] == 'Q')
- break;
-
- std::string::const_iterator iter = str.begin();
- std::string::const_iterator end = str.end();
- expression_ast ast;
- ast_print printer;
- bool r = phrase_parse(iter, end, calc, space, ast);
-
- if (r && iter == end)
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing succeeded\n";
- printer(ast);
- std::cout << "\n-------------------------\n";
- }
- else
- {
- std::string rest(iter, end);
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "stopped at: \": " << rest << "\"\n";
- std::cout << "-------------------------\n";
- }
- }
-
- std::cout << "Bye... :-) \n\n";
- return 0;
-}
-
-

Deleted: trunk/libs/spirit/example/qi/calc2_ast2.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc2_ast2.cpp 2011-03-07 21:36:48 EST (Mon, 07 Mar 2011)
+++ (empty file)
@@ -1,266 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-///////////////////////////////////////////////////////////////////////////////
-//
-// A Calculator example demonstrating generation of AST
-//
-// [ JDG April 28, 2008 : For BoostCon 2008 ]
-// [ JDG February 18, 2011 : Pure attributes. No semantic actions. ]
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
-#define BOOST_SPIRIT_ALTERNATIVES_ALLOW_ATTR_COMPAT
-
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/variant/recursive_variant.hpp>
-#include <boost/variant/apply_visitor.hpp>
-#include <boost/fusion/include/adapt_struct.hpp>
-#include <boost/foreach.hpp>
-
-#include <iostream>
-#include <string>
-
-namespace client { namespace ast
-{
- struct nil {};
- struct signed_;
- struct operation;
-
- typedef boost::variant<
- nil
- , unsigned int
- , boost::recursive_wrapper<signed_>
- , boost::recursive_wrapper<program>
- >
- operand;
-
- struct signed_
- {
- char sign;
- operand operand_;
- };
-
- struct operation
- {
- char operator_;
- operand operand_;
- };
-
- struct program
- {
- operand first;
- std::list<operation> rest;
- };
-}}
-
-BOOST_FUSION_ADAPT_STRUCT(
- client::ast::signed_,
- (char, sign)
- (client::ast::operand, operand_)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- client::ast::operation,
- (char, operator_)
- (client::ast::operand, operand_)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- client::ast::program,
- (client::ast::operand, first)
- (std::list<client::ast::operation>, rest)
-)
-
-namespace client { namespace ast
-{
- struct printer
- {
- typedef void result_type;
-
- void operator()(nil) const {}
- void operator()(unsigned int n) const { std::cout << n; }
-
- void operator()(operation const& x) const
- {
- boost::apply_visitor(*this, x.operand_);
- switch (x.operator_)
- {
- case '+': std::cout << " add"; break;
- case '-': std::cout << " subt"; break;
- case '*': std::cout << " mult"; break;
- case '/': std::cout << " div"; break;
- }
- }
-
- void operator()(signed_ const& x) const
- {
- boost::apply_visitor(*this, x.operand_);
- switch (x.sign)
- {
- case '-': std::cout << " neg"; break;
- case '+': std::cout << " pos"; break;
- }
- }
-
- void operator()(program const& x) const
- {
- boost::apply_visitor(*this, x.first);
- BOOST_FOREACH(operation const& oper, x.rest)
- {
- std::cout << ' ';
- (*this)(oper);
- }
- }
- };
-
- struct eval
- {
- typedef int result_type;
-
- int operator()(nil) const { BOOST_ASSERT(0); return 0; }
- int operator()(unsigned int n) const { return n; }
-
- int operator()(operation const& x, int lhs) const
- {
- int rhs = boost::apply_visitor(*this, x.operand_);
- switch (x.operator_)
- {
- case '+': return lhs + rhs;
- case '-': return lhs - rhs;
- case '*': return lhs * rhs;
- case '/': return lhs / rhs;
- }
- BOOST_ASSERT(0);
- return 0;
- }
-
- int operator()(signed_ const& x) const
- {
- int rhs = boost::apply_visitor(*this, x.operand_);
- switch (x.sign)
- {
- case '-': return -rhs;
- case '+': return +rhs;
- }
- BOOST_ASSERT(0);
- return 0;
- }
-
- int operator()(program const& x) const
- {
- int state = boost::apply_visitor(*this, x.first);
- BOOST_FOREACH(operation const& oper, x.rest)
- {
- state = (*this)(oper, state);
- }
- return state;
- }
- };
-}}
-
-namespace client
-{
- namespace qi = boost::spirit::qi;
- namespace ascii = boost::spirit::ascii;
-
- ///////////////////////////////////////////////////////////////////////////////
- // Our calculator grammar
- ///////////////////////////////////////////////////////////////////////////////
- template <typename Iterator>
- struct calculator : qi::grammar<Iterator, ast::program(), ascii::space_type>
- {
- calculator() : calculator::base_type(expression)
- {
- qi::uint_type uint_;
- qi::char_type char_;
-
- expression =
- term
- >> *( (char_('+') >> term)
- | (char_('-') >> term)
- )
- ;
-
- term =
- factor
- >> *( (char_('*') >> factor)
- | (char_('/') >> factor)
- )
- ;
-
- factor =
- uint_
- | '(' >> expression >> ')'
- | (char_('-') >> factor)
- | (char_('+') >> factor)
- ;
- }
-
- qi::rule<Iterator, ast::program(), ascii::space_type> expression;
- qi::rule<Iterator, ast::program(), ascii::space_type> term;
- qi::rule<Iterator, ast::operand(), ascii::space_type> factor;
- };
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Expression parser...\n\n";
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Type an expression...or [q or Q] to quit\n\n";
-
- typedef std::string::const_iterator iterator_type;
- typedef client::calculator<iterator_type> calculator;
- typedef client::ast::program ast_program;
- typedef client::ast::printer ast_print;
- typedef client::ast::eval ast_eval;
-
- std::string str;
- while (std::getline(std::cin, str))
- {
- if (str.empty() || str[0] == 'q' || str[0] == 'Q')
- break;
-
- 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();
- 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(program);
- std::cout << "\nResult: " << eval(program) << std::endl;
- std::cout << "-------------------------\n";
- }
- else
- {
- std::string rest(iter, end);
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "stopped at: \": " << rest << "\"\n";
- std::cout << "-------------------------\n";
- }
- }
-
- std::cout << "Bye... :-) \n\n";
- return 0;
-}
-
-

Deleted: trunk/libs/spirit/example/qi/calc3.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc3.cpp 2011-03-07 21:36:48 EST (Mon, 07 Mar 2011)
+++ (empty file)
@@ -1,117 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-///////////////////////////////////////////////////////////////////////////////
-//
-// A calculator example demonstrating the grammar and semantic actions
-// using phoenix to do the actual expression evaluation. The parser is
-// essentially an "interpreter" that evaluates expressions on the fly.
-//
-// [ JDG June 29, 2002 ] spirit1
-// [ JDG March 5, 2007 ] spirit2
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-
-#include <iostream>
-#include <string>
-
-namespace client
-{
- namespace qi = boost::spirit::qi;
- namespace ascii = boost::spirit::ascii;
-
- ///////////////////////////////////////////////////////////////////////////
- // Our calculator grammar
- ///////////////////////////////////////////////////////////////////////////
- template <typename Iterator>
- struct calculator : qi::grammar<Iterator, int(), ascii::space_type>
- {
- calculator() : calculator::base_type(expression)
- {
- using qi::_val;
- using qi::_1;
- using qi::uint_;
-
- expression =
- term [_val = _1]
- >> *( ('+' >> term [_val += _1])
- | ('-' >> term [_val -= _1])
- )
- ;
-
- term =
- factor [_val = _1]
- >> *( ('*' >> factor [_val *= _1])
- | ('/' >> factor [_val /= _1])
- )
- ;
-
- factor =
- uint_ [_val = _1]
- | '(' >> expression [_val = _1] >> ')'
- | ('-' >> factor [_val = -_1])
- | ('+' >> factor [_val = _1])
- ;
- }
-
- qi::rule<Iterator, int(), ascii::space_type> expression, term, factor;
- };
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Expression parser...\n\n";
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Type an expression...or [q or Q] to quit\n\n";
-
- using boost::spirit::ascii::space;
- typedef std::string::const_iterator iterator_type;
- typedef client::calculator<iterator_type> calculator;
-
- calculator calc; // Our grammar
-
- std::string str;
- int result;
- while (std::getline(std::cin, str))
- {
- if (str.empty() || str[0] == 'q' || str[0] == 'Q')
- break;
-
- std::string::const_iterator iter = str.begin();
- std::string::const_iterator end = str.end();
- bool r = phrase_parse(iter, end, calc, space, result);
-
- if (r && iter == end)
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing succeeded\n";
- std::cout << "result = " << result << std::endl;
- std::cout << "-------------------------\n";
- }
- else
- {
- std::string rest(iter, end);
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "stopped at: \": " << rest << "\"\n";
- std::cout << "-------------------------\n";
- }
- }
-
- std::cout << "Bye... :-) \n\n";
- return 0;
-}
-
-

Deleted: trunk/libs/spirit/example/qi/calc4.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc4.cpp 2011-03-07 21:36:48 EST (Mon, 07 Mar 2011)
+++ (empty file)
@@ -1,135 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-///////////////////////////////////////////////////////////////////////////////
-//
-// This time, we'll incorporate error handling and reporting.
-//
-// [ JDG June 29, 2002 ] spirit1
-// [ JDG March 5, 2007 ] spirit2
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-#include <boost/spirit/include/phoenix_object.hpp>
-
-#include <iostream>
-#include <string>
-
-namespace client
-{
- namespace qi = boost::spirit::qi;
- namespace phoenix = boost::phoenix;
- namespace ascii = boost::spirit::ascii;
-
- ///////////////////////////////////////////////////////////////////////////////
- // Our calculator grammar
- ///////////////////////////////////////////////////////////////////////////////
- template <typename Iterator>
- struct calculator : qi::grammar<Iterator, int(), ascii::space_type>
- {
- calculator() : calculator::base_type(expression)
- {
- using namespace qi::labels;
- using qi::uint_;
- using qi::on_error;
- using qi::fail;
-
- using phoenix::construct;
- using phoenix::val;
-
- expression =
- term [_val = _1]
- >> *( ('+' > term [_val += _1])
- | ('-' > term [_val -= _1])
- )
- ;
-
- term =
- factor [_val = _1]
- >> *( ('*' > factor [_val *= _1])
- | ('/' > factor [_val /= _1])
- )
- ;
-
- factor =
- uint_ [_val = _1]
- | '(' > expression [_val = _1] > ')'
- | ('-' > factor [_val = -_1])
- | ('+' > factor [_val = _1])
- ;
-
- expression.name("expression");
- term.name("term");
- factor.name("factor");
-
- on_error<fail>
- (
- expression
- , std::cout
- << val("Error! Expecting ")
- << _4 // what failed?
- << val(" here: \"")
- << construct<std::string>(_3, _2) // iterators to error-pos, end
- << val("\"")
- << std::endl
- );
- }
-
- qi::rule<Iterator, int(), ascii::space_type> expression, term, factor;
- };
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Expression parser...\n\n";
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Type an expression...or [q or Q] to quit\n\n";
-
- using boost::spirit::ascii::space;
- typedef std::string::const_iterator iterator_type;
- typedef client::calculator<iterator_type> calculator;
-
- calculator calc; // Our grammar
-
- std::string str;
- int result;
- while (std::getline(std::cin, str))
- {
- if (str.empty() || str[0] == 'q' || str[0] == 'Q')
- break;
-
- std::string::const_iterator iter = str.begin();
- std::string::const_iterator end = str.end();
- bool r = phrase_parse(iter, end, calc, space, result);
-
- if (r && iter == end)
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing succeeded\n";
- std::cout << "result = " << result << std::endl;
- std::cout << "-------------------------\n";
- }
- else
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "-------------------------\n";
- }
- }
-
- std::cout << "Bye... :-) \n\n";
- return 0;
-}
-
-

Deleted: trunk/libs/spirit/example/qi/calc4_debug.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc4_debug.cpp 2011-03-07 21:36:48 EST (Mon, 07 Mar 2011)
+++ (empty file)
@@ -1,140 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-///////////////////////////////////////////////////////////////////////////////
-//
-// Same as cal4, but with debugging enabled.
-//
-// [ JDG June 29, 2002 ] spirit1
-// [ JDG March 5, 2007 ] spirit2
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-#include <boost/spirit/include/phoenix_object.hpp>
-
-#include <iostream>
-#include <string>
-
-namespace client
-{
- namespace qi = boost::spirit::qi;
- namespace phoenix = boost::phoenix;
- namespace ascii = boost::spirit::ascii;
-
- ///////////////////////////////////////////////////////////////////////////////
- // Our calculator grammar
- ///////////////////////////////////////////////////////////////////////////////
- template <typename Iterator>
- struct calculator : qi::grammar<Iterator, int(), ascii::space_type>
- {
- calculator() : calculator::base_type(expression)
- {
- using namespace qi::labels;
- using qi::uint_;
- using qi::on_error;
- using qi::fail;
- using qi::debug;
-
- using phoenix::construct;
- using phoenix::val;
-
- expression =
- term [_val = _1]
- >> *( ('+' > term [_val += _1])
- | ('-' > term [_val -= _1])
- )
- ;
-
- term =
- factor [_val = _1]
- >> *( ('*' > factor [_val *= _1])
- | ('/' > factor [_val /= _1])
- )
- ;
-
- factor =
- uint_ [_val = _1]
- | '(' > expression [_val = _1] > ')'
- | ('-' > factor [_val = -_1])
- | ('+' > factor [_val = _1])
- ;
-
- expression.name("expression");
- term.name("term");
- factor.name("factor");
-
- on_error<fail>
- (
- expression
- , std::cout
- << val("Error! Expecting ")
- << _4 // what failed?
- << val(" here: \"")
- << construct<std::string>(_3, _2) // iterators to error-pos, end
- << val("\"")
- << std::endl
- );
-
- debug(expression);
- debug(term);
- debug(factor);
- }
-
- qi::rule<Iterator, int(), ascii::space_type> expression, term, factor;
- };
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Expression parser...\n\n";
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Type an expression...or [q or Q] to quit\n\n";
-
- using boost::spirit::ascii::space;
- typedef std::string::const_iterator iterator_type;
- typedef client::calculator<iterator_type> calculator;
-
- calculator calc; // Our grammar
-
- std::string str;
- int result;
- while (std::getline(std::cin, str))
- {
- if (str.empty() || str[0] == 'q' || str[0] == 'Q')
- break;
-
- std::string::const_iterator iter = str.begin();
- std::string::const_iterator end = str.end();
- bool r = phrase_parse(iter, end, calc, space, result);
-
- if (r && iter == end)
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing succeeded\n";
- std::cout << "result = " << result << std::endl;
- std::cout << "-------------------------\n";
- }
- else
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "-------------------------\n";
- }
- }
-
- std::cout << "Bye... :-) \n\n";
- return 0;
-}
-
-

Deleted: trunk/libs/spirit/example/qi/calc5.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc5.cpp 2011-03-07 21:36:48 EST (Mon, 07 Mar 2011)
+++ (empty file)
@@ -1,235 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-///////////////////////////////////////////////////////////////////////////////
-//
-// Yet another calculator example! This time, we will compile to a simple
-// virtual machine. This is actually one of the very first Spirit example
-// circa 2000. Now, it's ported to Spirit2.
-//
-// [ JDG Sometime 2000 ] pre-boost
-// [ JDG September 18, 2002 ] spirit1
-// [ JDG April 8, 2007 ] spirit2
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/phoenix_core.hpp>
-#include <boost/spirit/include/phoenix_container.hpp>
-#include <boost/spirit/include/phoenix_statement.hpp>
-#include <boost/spirit/include/phoenix_object.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-
-#include <iostream>
-#include <string>
-#include <vector>
-
-namespace client
-{
- namespace qi = boost::spirit::qi;
- namespace phoenix = boost::phoenix;
- namespace ascii = boost::spirit::ascii;
-
- ///////////////////////////////////////////////////////////////////////////
- // The Virtual Machine
- ///////////////////////////////////////////////////////////////////////////
- enum byte_code
- {
- op_neg, // negate the top stack entry
- op_add, // add top two stack entries
- op_sub, // subtract top two stack entries
- op_mul, // multiply top two stack entries
- op_div, // divide top two stack entries
- op_int, // push constant integer into the stack
- };
-
- class vmachine
- {
- public:
-
- vmachine(unsigned stackSize = 4096)
- : stack(stackSize)
- , stack_ptr(stack.begin())
- {
- }
-
- int top() const { return stack_ptr[-1]; };
- void execute(std::vector<int> const& code);
-
- private:
-
- std::vector<int> stack;
- std::vector<int>::iterator stack_ptr;
- };
-
- void vmachine::execute(std::vector<int> const& code)
- {
- std::vector<int>::const_iterator pc = code.begin();
- stack_ptr = stack.begin();
-
- while (pc != code.end())
- {
- switch (*pc++)
- {
- case op_neg:
- stack_ptr[-1] = -stack_ptr[-1];
- break;
-
- case op_add:
- --stack_ptr;
- stack_ptr[-1] += stack_ptr[0];
- break;
-
- case op_sub:
- --stack_ptr;
- stack_ptr[-1] -= stack_ptr[0];
- break;
-
- case op_mul:
- --stack_ptr;
- stack_ptr[-1] *= stack_ptr[0];
- break;
-
- case op_div:
- --stack_ptr;
- stack_ptr[-1] /= stack_ptr[0];
- break;
-
- case op_int:
- *stack_ptr++ = *pc++;
- break;
- }
- }
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // Our calculator grammar and compiler
- ///////////////////////////////////////////////////////////////////////////
- template <typename Iterator>
- struct calculator : qi::grammar<Iterator, ascii::space_type>
- {
- calculator(std::vector<int>& code)
- : calculator::base_type(expression)
- , code(code)
- {
- using namespace qi::labels;
- using qi::uint_;
- using qi::on_error;
- using qi::fail;
-
- using phoenix::val;
- using phoenix::ref;
- using phoenix::push_back;
- using phoenix::construct;
-
- expression =
- term
- >> *( ('+' > term [push_back(ref(code), op_add)])
- | ('-' > term [push_back(ref(code), op_sub)])
- )
- ;
-
- term =
- factor
- >> *( ('*' > factor [push_back(ref(code), op_mul)])
- | ('/' > factor [push_back(ref(code), op_div)])
- )
- ;
-
- factor =
- uint_ [
- push_back(ref(code), op_int),
- push_back(ref(code), _1)
- ]
- | '(' > expression > ')'
- | ('-' > factor [push_back(ref(code), op_neg)])
- | ('+' > factor)
- ;
-
- expression.name("expression");
- term.name("term");
- factor.name("factor");
-
- on_error<fail>
- (
- expression
- , std::cout
- << val("Error! Expecting ")
- << _4 // what failed?
- << val(" here: \"")
- << construct<std::string>(_3, _2) // iterators to error-pos, end
- << val("\"")
- << std::endl
- );
- }
-
- qi::rule<Iterator, ascii::space_type> expression, term, factor;
- std::vector<int>& code;
- };
-
- template <typename Grammar>
- bool compile(Grammar const& calc, std::string const& expr)
- {
- std::string::const_iterator iter = expr.begin();
- std::string::const_iterator end = expr.end();
- bool r = phrase_parse(iter, end, calc, ascii::space);
-
- if (r && iter == end)
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing succeeded\n";
- std::cout << "-------------------------\n";
- return true;
- }
- else
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "-------------------------\n";
- return false;
- }
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Expression parser...\n\n";
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Type an expression...or [q or Q] to quit\n\n";
-
- typedef std::string::const_iterator iterator_type;
- typedef client::calculator<iterator_type> calculator;
-
- client::vmachine mach; // Our virtual machine
- std::vector<int> code; // Our VM code
- calculator calc(code); // Our grammar
-
- std::string str;
- while (std::getline(std::cin, str))
- {
- if (str.empty() || str[0] == 'q' || str[0] == 'Q')
- break;
-
- code.clear();
- if (client::compile(calc, str))
- {
- mach.execute(code);
- std::cout << "\n\nresult = " << mach.top() << std::endl;
- std::cout << "-------------------------\n\n";
- }
- }
-
- std::cout << "Bye... :-) \n\n";
- return 0;
-}
-
-


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