|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72578 - in branches/release/libs/spirit/example: . qi qi/compiler_tutorial qi/compiler_tutorial/calc7 qi/compiler_tutorial/calc8 qi/compiler_tutorial/conjure qi/compiler_tutorial/conjure1 qi/compiler_tutorial/conjure2 qi/compiler_tutorial/conjure_lexer qi/compiler_tutorial/mini_c
From: hartmut.kaiser_at_[hidden]
Date: 2011-06-14 04:22:26
Author: hkaiser
Date: 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
New Revision: 72578
URL: http://svn.boost.org/trac/boost/changeset/72578
Log:
Spirit: merging from trunk, authorized by rene
Added:
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure1/
- copied from r72465, /trunk/libs/spirit/example/qi/compiler_tutorial/conjure1/
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/ (props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/annotation.hpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/ast.hpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/compiler.cpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/compiler.hpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/config.hpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/conjure_static_lexer.hpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/conjure_static_lexer_generate.cpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/conjure_static_switch_lexer.hpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/error_handler.hpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/expression.cpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/expression.hpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/expression_def.hpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/function.cpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/function.hpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/function_def.hpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/lexer.cpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/lexer.hpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/lexer_def.hpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/main.cpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/statement.cpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/statement.hpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/statement_def.hpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/token_ids.hpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/vm.cpp (contents, props changed)
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/vm.hpp (contents, props changed)
Removed:
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure/
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure_lexer/
Properties modified:
branches/release/libs/spirit/example/ (props changed)
Text files modified:
branches/release/libs/spirit/example/qi/compiler_tutorial/Jamfile | 30 +++++++++++++++---------------
branches/release/libs/spirit/example/qi/compiler_tutorial/calc7/compiler.cpp | 3 ++-
branches/release/libs/spirit/example/qi/compiler_tutorial/calc8/compiler.cpp | 3 ++-
branches/release/libs/spirit/example/qi/compiler_tutorial/conjure1/compiler.cpp | 3 ++-
branches/release/libs/spirit/example/qi/compiler_tutorial/mini_c/compiler.cpp | 3 ++-
branches/release/libs/spirit/example/qi/parse_date.cpp | 1 -
6 files changed, 23 insertions(+), 20 deletions(-)
Modified: branches/release/libs/spirit/example/qi/compiler_tutorial/Jamfile
==============================================================================
--- branches/release/libs/spirit/example/qi/compiler_tutorial/Jamfile (original)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/Jamfile 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -44,23 +44,23 @@
mini_c/main.cpp
;
-exe conjure :
- conjure/vm.cpp
- conjure/compiler.cpp
- conjure/expression.cpp
- conjure/statement.cpp
- conjure/function.cpp
- conjure/main.cpp
+exe conjure1 :
+ conjure1/vm.cpp
+ conjure1/compiler.cpp
+ conjure1/expression.cpp
+ conjure1/statement.cpp
+ conjure1/function.cpp
+ conjure1/main.cpp
;
-exe conjure_lexer :
- conjure_lexer/compiler.cpp
- conjure_lexer/expression.cpp
- conjure_lexer/function.cpp
- conjure_lexer/lexer.cpp
- conjure_lexer/main.cpp
- conjure_lexer/statement.cpp
- conjure_lexer/vm.cpp
+exe conjure2 :
+ conjure2/compiler.cpp
+ conjure2/expression.cpp
+ conjure2/function.cpp
+ conjure2/lexer.cpp
+ conjure2/main.cpp
+ conjure2/statement.cpp
+ conjure2/vm.cpp
;
Modified: branches/release/libs/spirit/example/qi/compiler_tutorial/calc7/compiler.cpp
==============================================================================
--- branches/release/libs/spirit/example/qi/compiler_tutorial/calc7/compiler.cpp (original)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/calc7/compiler.cpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -40,7 +40,8 @@
void program::add_var(std::string const& name)
{
- variables[name] = variables.size();
+ std::size_t n = variables.size();
+ variables[name] = n;
}
void program::print_variables(std::vector<int> const& stack) const
Modified: branches/release/libs/spirit/example/qi/compiler_tutorial/calc8/compiler.cpp
==============================================================================
--- branches/release/libs/spirit/example/qi/compiler_tutorial/calc8/compiler.cpp (original)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/calc8/compiler.cpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -42,7 +42,8 @@
void program::add_var(std::string const& name)
{
- variables[name] = variables.size();
+ std::size_t n = variables.size();
+ variables[name] = n;
}
void program::print_variables(std::vector<int> const& stack) const
Modified: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure1/compiler.cpp
==============================================================================
--- /trunk/libs/spirit/example/qi/compiler_tutorial/conjure1/compiler.cpp (original)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure1/compiler.cpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -45,7 +45,8 @@
void function::add_var(std::string const& name)
{
- variables[name] = variables.size();
+ std::size_t n = variables.size();
+ variables[name] = n;
}
void function::link_to(std::string const& name, std::size_t address)
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/annotation.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/annotation.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,92 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_CONJURE_ANNOTATION_HPP)
+#define BOOST_SPIRIT_CONJURE_ANNOTATION_HPP
+
+#include <map>
+#include <boost/variant/apply_visitor.hpp>
+#include <boost/type_traits/is_base_of.hpp>
+#include <boost/mpl/bool.hpp>
+#include "ast.hpp"
+
+namespace client
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // The annotation handler links the AST to a map of iterator positions
+ // for the purpose of subsequent semantic error handling when the
+ // program is being compiled.
+ ///////////////////////////////////////////////////////////////////////////////
+ template <typename Iterator>
+ struct annotation
+ {
+ template <typename, typename>
+ struct result { typedef void type; };
+
+ std::vector<Iterator>& iters;
+ annotation(std::vector<Iterator>& iters)
+ : iters(iters) {}
+
+ struct set_id
+ {
+ typedef void result_type;
+
+ int id;
+ set_id(int id) : id(id) {}
+
+ template <typename T>
+ void operator()(T& x) const
+ {
+ this->dispatch(x, boost::is_base_of<ast::tagged, T>());
+ }
+
+ // This will catch all nodes except those inheriting from ast::tagged
+ template <typename T>
+ void dispatch(T& x, boost::mpl::false_) const
+ {
+ // (no-op) no need for tags
+ }
+
+ // This will catch all nodes inheriting from ast::tagged
+ template <typename T>
+ void dispatch(T& x, boost::mpl::true_) const
+ {
+ x.id = id;
+ }
+ };
+
+ void operator()(ast::operand& ast, Iterator pos) const
+ {
+ int id = iters.size();
+ iters.push_back(pos);
+ boost::apply_visitor(set_id(id), ast);
+ }
+
+ void operator()(ast::assignment& ast, Iterator pos) const
+ {
+ int id = iters.size();
+ iters.push_back(pos);
+ ast.lhs.id = id;
+ }
+
+ void operator()(ast::return_statement& ast, Iterator pos) const
+ {
+ int id = iters.size();
+ iters.push_back(pos);
+ ast.id = id;
+ }
+
+ void operator()(ast::identifier& ast, Iterator pos) const
+ {
+ int id = iters.size();
+ iters.push_back(pos);
+ ast.id = id;
+ }
+ };
+}
+
+#endif
+
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/ast.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/ast.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,287 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_CONJURE_AST_HPP)
+#define BOOST_SPIRIT_CONJURE_AST_HPP
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/variant/recursive_variant.hpp>
+#include <boost/fusion/include/adapt_struct.hpp>
+#include <boost/fusion/include/io.hpp>
+#include <boost/optional.hpp>
+#include <list>
+
+#include "token_ids.hpp"
+
+namespace client { namespace ast
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // The AST
+ ///////////////////////////////////////////////////////////////////////////
+ struct tagged
+ {
+ int id; // Used to annotate the AST with the iterator position.
+ // This id is used as a key to a map<int, Iterator>
+ // (not really part of the AST.)
+ };
+
+ struct nil {};
+ struct unary;
+ struct function_call;
+ struct expression;
+
+ struct identifier : tagged
+ {
+ identifier(std::string const& name = "") : name(name) {}
+ std::string name;
+ };
+
+ typedef boost::variant<
+ nil
+ , bool
+ , unsigned int
+ , identifier
+ , boost::recursive_wrapper<unary>
+ , boost::recursive_wrapper<function_call>
+ , boost::recursive_wrapper<expression>
+ >
+ operand;
+
+ #define OP(id) (id + op_operator)
+ #define OP_EX(id, mask) (id + (mask | op_operator))
+
+ enum optoken
+ {
+ // pseudo tags
+ op_operator = lexer::ID_OP_OPERATOR,
+ op_binary = lexer::ID_OP_BINARY,
+ op_unary = lexer::ID_OP_UNARY,
+ op_mask = (op_operator | op_unary | op_binary),
+
+ // precedence 1
+ op_comma = OP(0),
+
+ // precedence 2
+ op_assign = OP(1),
+ op_plus_assign = OP(2),
+ op_minus_assign = OP(3),
+ op_times_assign = OP(4),
+ op_divide_assign = OP(5),
+ op_mod_assign = OP(6),
+ op_bit_and_assign = OP(7),
+ op_bit_xor_assign = OP(8),
+ op_bitor_assign = OP(9),
+ op_shift_left_assign = OP(10),
+ op_shift_right_assign = OP(11),
+
+ // precedence 3
+ op_logical_or = OP_EX(12, op_binary),
+
+ // precedence 4
+ op_logical_and = OP_EX(13, op_binary),
+
+ // precedence 5
+ op_bit_or = OP_EX(14, op_binary),
+
+ // precedence 6
+ op_bit_xor = OP_EX(15, op_binary),
+
+ // precedence 7
+ op_bit_and = OP_EX(16, op_binary),
+
+ // precedence 8
+ op_equal = OP_EX(17, op_binary),
+ op_not_equal = OP_EX(18, op_binary),
+
+ // precedence 9
+ op_less = OP_EX(19, op_binary),
+ op_less_equal = OP_EX(20, op_binary),
+ op_greater = OP_EX(21, op_binary),
+ op_greater_equal = OP_EX(22, op_binary),
+
+ // precedence 10
+ op_shift_left = OP_EX(23, op_binary),
+ op_shift_right = OP_EX(24, op_binary),
+
+ // precedence 11
+ op_plus = OP_EX(25, op_binary|op_unary),
+ op_minus = OP_EX(26, op_binary|op_unary),
+
+ // precedence 12
+ op_times = OP_EX(27, op_binary),
+ op_divide = OP_EX(28, op_binary),
+ op_mod = OP_EX(29, op_binary),
+
+ // precedence 13
+ op_positive = OP_EX(30, op_unary),
+ op_negative = OP_EX(31, op_unary),
+ op_pre_incr = OP_EX(32, op_unary),
+ op_pre_decr = OP_EX(33, op_unary),
+ op_compl = OP_EX(34, op_unary),
+ op_not = OP_EX(35, op_unary),
+
+ // precedence 14
+ op_post_incr = OP(36),
+ op_post_decr = OP(37)
+ };
+
+ struct unary
+ {
+ optoken operator_;
+ operand operand_;
+ };
+
+ struct operation
+ {
+ optoken operator_;
+ operand operand_;
+ };
+
+ struct function_call
+ {
+ identifier function_name;
+ std::list<expression> args;
+ };
+
+ struct expression
+ {
+ operand first;
+ std::list<operation> rest;
+ };
+
+ struct assignment
+ {
+ identifier lhs;
+ expression rhs;
+ };
+
+ struct variable_declaration
+ {
+ identifier lhs;
+ boost::optional<expression> rhs;
+ };
+
+ struct if_statement;
+ struct while_statement;
+ struct statement_list;
+ struct return_statement;
+
+ typedef boost::variant<
+ variable_declaration
+ , assignment
+ , boost::recursive_wrapper<if_statement>
+ , boost::recursive_wrapper<while_statement>
+ , boost::recursive_wrapper<return_statement>
+ , boost::recursive_wrapper<statement_list>
+ >
+ statement;
+
+ struct statement_list : std::list<statement> {};
+
+ struct if_statement
+ {
+ expression condition;
+ statement then;
+ boost::optional<statement> else_;
+ };
+
+ struct while_statement
+ {
+ expression condition;
+ statement body;
+ };
+
+ struct return_statement : tagged
+ {
+ boost::optional<expression> expr;
+ };
+
+ struct function
+ {
+ std::string return_type;
+ identifier function_name;
+ std::list<identifier> args;
+ statement_list body;
+ };
+
+ typedef std::list<function> function_list;
+
+ // print functions for debugging
+ inline std::ostream& operator<<(std::ostream& out, nil)
+ {
+ out << "nil"; return out;
+ }
+
+ inline std::ostream& operator<<(std::ostream& out, identifier const& id)
+ {
+ out << id.name; return out;
+ }
+}}
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::unary,
+ (client::ast::optoken, operator_)
+ (client::ast::operand, operand_)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::operation,
+ (client::ast::optoken, operator_)
+ (client::ast::operand, operand_)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::function_call,
+ (client::ast::identifier, function_name)
+ (std::list<client::ast::expression>, args)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::expression,
+ (client::ast::operand, first)
+ (std::list<client::ast::operation>, rest)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::variable_declaration,
+ (client::ast::identifier, lhs)
+ (boost::optional<client::ast::expression>, rhs)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::assignment,
+ (client::ast::identifier, lhs)
+ (client::ast::expression, rhs)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::if_statement,
+ (client::ast::expression, condition)
+ (client::ast::statement, then)
+ (boost::optional<client::ast::statement>, else_)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::while_statement,
+ (client::ast::expression, condition)
+ (client::ast::statement, body)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::return_statement,
+ (boost::optional<client::ast::expression>, expr)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ client::ast::function,
+ (std::string, return_type)
+ (client::ast::identifier, function_name)
+ (std::list<client::ast::identifier>, args)
+ (client::ast::statement_list, body)
+)
+
+#endif
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/compiler.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/compiler.cpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,642 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#include "config.hpp"
+#include "compiler.hpp"
+#include "vm.hpp"
+#include <boost/foreach.hpp>
+#include <boost/variant/apply_visitor.hpp>
+#include <boost/assert.hpp>
+#include <boost/lexical_cast.hpp>
+#include <set>
+
+namespace client { namespace code_gen
+{
+ void function::op(int a)
+ {
+ code.push_back(a);
+ size_ += 1;
+ }
+
+ void function::op(int a, int b)
+ {
+ code.push_back(a);
+ code.push_back(b);
+ size_ += 2;
+ }
+
+ void function::op(int a, int b, int c)
+ {
+ code.push_back(a);
+ code.push_back(b);
+ code.push_back(c);
+ size_ += 3;
+ }
+
+ int const* function::find_var(std::string const& name) const
+ {
+ std::map<std::string, int>::const_iterator i = variables.find(name);
+ if (i == variables.end())
+ return 0;
+ return &i->second;
+ }
+
+ void function::add_var(std::string const& name)
+ {
+ std::size_t n = variables.size();
+ variables[name] = n;
+ }
+
+ void function::link_to(std::string const& name, std::size_t address)
+ {
+ function_calls[address] = name;
+ }
+
+ void function::print_assembler() const
+ {
+ std::vector<int>::const_iterator pc = code.begin() + address;
+
+ std::vector<std::string> locals(variables.size());
+ typedef std::pair<std::string, int> pair;
+ BOOST_FOREACH(pair const& p, variables)
+ {
+ locals[p.second] = p.first;
+ std::cout << " local "
+ << p.first << ", @" << p.second << std::endl;
+ }
+
+ std::map<std::size_t, std::string> lines;
+ std::set<std::size_t> jumps;
+
+ while (pc != (code.begin() + address + size_))
+ {
+ std::string line;
+ std::size_t address = pc - code.begin();
+
+ switch (*pc++)
+ {
+ case op_neg:
+ line += " op_neg";
+ break;
+
+ case op_not:
+ line += " op_not";
+ break;
+
+ case op_add:
+ line += " op_add";
+ break;
+
+ case op_sub:
+ line += " op_sub";
+ break;
+
+ case op_mul:
+ line += " op_mul";
+ break;
+
+ case op_div:
+ line += " op_div";
+ break;
+
+ case op_eq:
+ line += " op_eq";
+ break;
+
+ case op_neq:
+ line += " op_neq";
+ break;
+
+ case op_lt:
+ line += " op_lt";
+ break;
+
+ case op_lte:
+ line += " op_lte";
+ break;
+
+ case op_gt:
+ line += " op_gt";
+ break;
+
+ case op_gte:
+ line += " op_gte";
+ break;
+
+ case op_and:
+ line += " op_and";
+ break;
+
+ case op_or:
+ line += " op_or";
+ break;
+
+ case op_load:
+ line += " op_load ";
+ line += boost::lexical_cast<std::string>(locals[*pc++]);
+ break;
+
+ case op_store:
+ line += " op_store ";
+ line += boost::lexical_cast<std::string>(locals[*pc++]);
+ break;
+
+ case op_int:
+ line += " op_int ";
+ line += boost::lexical_cast<std::string>(*pc++);
+ break;
+
+ case op_true:
+ line += " op_true";
+ break;
+
+ case op_false:
+ line += " op_false";
+ break;
+
+ case op_jump:
+ {
+ line += " op_jump ";
+ std::size_t pos = (pc - code.begin()) + *pc++;
+ if (pos == code.size())
+ line += "end";
+ else
+ line += boost::lexical_cast<std::string>(pos);
+ jumps.insert(pos);
+ }
+ break;
+
+ case op_jump_if:
+ {
+ line += " op_jump_if ";
+ std::size_t pos = (pc - code.begin()) + *pc++;
+ if (pos == code.size())
+ line += "end";
+ else
+ line += boost::lexical_cast<std::string>(pos);
+ jumps.insert(pos);
+ }
+ break;
+
+ case op_call:
+ {
+ line += " op_call ";
+ int nargs = *pc++;
+ std::size_t jump = *pc++;
+ line += boost::lexical_cast<std::string>(nargs) + ", ";
+ BOOST_ASSERT(function_calls.find(jump) != function_calls.end());
+ line += function_calls.find(jump)->second;
+ }
+ break;
+
+ case op_stk_adj:
+ line += " op_stk_adj ";
+ line += boost::lexical_cast<std::string>(*pc++);
+ break;
+
+
+ case op_return:
+ line += " op_return";
+ break;
+ }
+ lines[address] = line;
+ }
+
+ std::cout << "start:" << std::endl;
+ typedef std::pair<std::size_t, std::string> line_info;
+ BOOST_FOREACH(line_info const& l, lines)
+ {
+ std::size_t pos = l.first;
+ if (jumps.find(pos) != jumps.end())
+ std::cout << pos << ':' << std::endl;
+ std::cout << l.second << std::endl;
+ }
+
+ std::cout << "end:" << std::endl << std::endl;
+ }
+
+ bool compiler::operator()(unsigned int x)
+ {
+ BOOST_ASSERT(current != 0);
+ current->op(op_int, x);
+ return true;
+ }
+
+ bool compiler::operator()(bool x)
+ {
+ BOOST_ASSERT(current != 0);
+ current->op(x ? op_true : op_false);
+ return true;
+ }
+
+ bool compiler::operator()(ast::identifier const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ int const* p = current->find_var(x.name);
+ if (p == 0)
+ {
+ std::cout << x.id << std::endl;
+ error_handler(x.id, "Undeclared variable: " + x.name);
+ return false;
+ }
+ current->op(op_load, *p);
+ return true;
+ }
+
+ bool compiler::operator()(ast::optoken const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ switch (x)
+ {
+ case ast::op_plus: current->op(op_add); break;
+ case ast::op_minus: current->op(op_sub); break;
+ case ast::op_times: current->op(op_mul); break;
+ case ast::op_divide: current->op(op_div); break;
+
+ case ast::op_equal: current->op(op_eq); break;
+ case ast::op_not_equal: current->op(op_neq); break;
+ case ast::op_less: current->op(op_lt); break;
+ case ast::op_less_equal: current->op(op_lte); break;
+ case ast::op_greater: current->op(op_gt); break;
+ case ast::op_greater_equal: current->op(op_gte); break;
+
+ case ast::op_logical_or: current->op(op_or); break;
+ case ast::op_logical_and: current->op(op_and); break;
+ default: BOOST_ASSERT(0); return false;
+ }
+ return true;
+ }
+
+ bool compiler::operator()(ast::unary const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ if (!boost::apply_visitor(*this, x.operand_))
+ return false;
+ switch (x.operator_)
+ {
+ case ast::op_minus: current->op(op_neg); break;
+ case ast::op_not: current->op(op_not); break;
+ case ast::op_plus: break;
+ default: BOOST_ASSERT(0); return false;
+ }
+ return true;
+ }
+
+ bool compiler::operator()(ast::function_call const& x)
+ {
+ BOOST_ASSERT(current != 0);
+
+ if (functions.find(x.function_name.name) == functions.end())
+ {
+ std::cout << x.function_name.id << std::endl;
+ error_handler(x.function_name.id, "Function not found: " + x.function_name.name);
+ return false;
+ }
+
+ boost::shared_ptr<code_gen::function> p = functions[x.function_name.name];
+
+ if (p->nargs() != x.args.size())
+ {
+ std::cout << x.function_name.id << std::endl;
+ error_handler(x.function_name.id, "Wrong number of arguments: " + x.function_name.name);
+ return false;
+ }
+
+ BOOST_FOREACH(ast::expression const& expr, x.args)
+ {
+ if (!(*this)(expr))
+ return false;
+ }
+
+ current->op(
+ op_call,
+ p->nargs(),
+ p->get_address());
+ current->link_to(x.function_name.name, p->get_address());
+
+ return true;
+ }
+
+ namespace
+ {
+ int precedence[] = {
+ // precedence 1
+ 1, // op_comma
+
+ // precedence 2
+ 2, // op_assign
+ 2, // op_plus_assign
+ 2, // op_minus_assign
+ 2, // op_times_assign
+ 2, // op_divide_assign
+ 2, // op_mod_assign
+ 2, // op_bit_and_assign
+ 2, // op_bit_xor_assign
+ 2, // op_bitor_assign
+ 2, // op_shift_left_assign
+ 2, // op_shift_right_assign
+
+ // precedence 3
+ 3, // op_logical_or
+
+ // precedence 4
+ 4, // op_logical_and
+
+ // precedence 5
+ 5, // op_bit_or
+
+ // precedence 6
+ 6, // op_bit_xor
+
+ // precedence 7
+ 7, // op_bit_and
+
+ // precedence 8
+ 8, // op_equal
+ 8, // op_not_equal
+
+ // precedence 9
+ 9, // op_less
+ 9, // op_less_equal
+ 9, // op_greater
+ 9, // op_greater_equal
+
+ // precedence 10
+ 10, // op_shift_left
+ 10, // op_shift_right
+
+ // precedence 11
+ 11, // op_plus
+ 11, // op_minus
+
+ // precedence 12
+ 12, // op_times
+ 12, // op_divide
+ 12, // op_mod
+
+ // precedence 13
+ 13, // op_positive
+ 13, // op_negative
+ 13, // op_pre_incr
+ 13, // op_pre_decr
+ 13, // op_compl
+ 13, // op_not
+
+ // precedence 14
+ 14, // op_post_incr
+ 14 // op_post_decr
+ };
+ }
+
+ inline int get_precedence(ast::optoken op)
+ {
+ return precedence[op & ~ast::op_mask];
+ }
+
+ // The Shunting-yard algorithm
+ bool compiler::compile_expression(
+ int min_precedence,
+ std::list<ast::operation>::const_iterator& rbegin,
+ std::list<ast::operation>::const_iterator rend)
+ {
+ while ((rbegin != rend) && (get_precedence(rbegin->operator_) >= min_precedence))
+ {
+ ast::optoken op = rbegin->operator_;
+ if (!boost::apply_visitor(*this, rbegin->operand_))
+ return false;
+ ++rbegin;
+
+ while ((rbegin != rend) && (get_precedence(rbegin->operator_) > get_precedence(op)))
+ {
+ ast::optoken next_op = rbegin->operator_;
+ compile_expression(get_precedence(next_op), rbegin, rend);
+ }
+ (*this)(op);
+ }
+ return true;
+ }
+
+ bool compiler::operator()(ast::expression const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ if (!boost::apply_visitor(*this, x.first))
+ return false;
+ std::list<ast::operation>::const_iterator rbegin = x.rest.begin();
+ if (!compile_expression(0, rbegin, x.rest.end()))
+ return false;
+ return true;
+ }
+
+ bool compiler::operator()(ast::assignment const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ if (!(*this)(x.rhs))
+ return false;
+ int const* p = current->find_var(x.lhs.name);
+ if (p == 0)
+ {
+ std::cout << x.lhs.id << std::endl;
+ error_handler(x.lhs.id, "Undeclared variable: " + x.lhs.name);
+ return false;
+ }
+ current->op(op_store, *p);
+ return true;
+ }
+
+ bool compiler::operator()(ast::variable_declaration const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ int const* p = current->find_var(x.lhs.name);
+ if (p != 0)
+ {
+ std::cout << x.lhs.id << std::endl;
+ error_handler(x.lhs.id, "Duplicate variable: " + x.lhs.name);
+ return false;
+ }
+ if (x.rhs) // if there's an RHS initializer
+ {
+ bool r = (*this)(*x.rhs);
+ if (r) // don't add the variable if the RHS fails
+ {
+ current->add_var(x.lhs.name);
+ current->op(op_store, *current->find_var(x.lhs.name));
+ }
+ return r;
+ }
+ else
+ {
+ current->add_var(x.lhs.name);
+ }
+ return true;
+ }
+
+ bool compiler::operator()(ast::statement const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ return boost::apply_visitor(*this, x);
+ }
+
+ bool compiler::operator()(ast::statement_list const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ BOOST_FOREACH(ast::statement const& s, x)
+ {
+ if (!(*this)(s))
+ return false;
+ }
+ return true;
+ }
+
+ bool compiler::operator()(ast::if_statement const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ if (!(*this)(x.condition))
+ return false;
+ current->op(op_jump_if, 0); // we shall fill this (0) in later
+ std::size_t skip = current->size()-1; // mark its position
+ if (!(*this)(x.then))
+ return false;
+ (*current)[skip] = current->size()-skip; // now we know where to jump to (after the if branch)
+
+ if (x.else_) // We got an alse
+ {
+ (*current)[skip] += 2; // adjust for the "else" jump
+ current->op(op_jump, 0); // we shall fill this (0) in later
+ std::size_t exit = current->size()-1; // mark its position
+ if (!(*this)(*x.else_))
+ return false;
+ (*current)[exit] = current->size()-exit;// now we know where to jump to (after the else branch)
+ }
+
+ return true;
+ }
+
+ bool compiler::operator()(ast::while_statement const& x)
+ {
+ BOOST_ASSERT(current != 0);
+ std::size_t loop = current->size(); // mark our position
+ if (!(*this)(x.condition))
+ return false;
+ current->op(op_jump_if, 0); // we shall fill this (0) in later
+ std::size_t exit = current->size()-1; // mark its position
+ if (!(*this)(x.body))
+ return false;
+ current->op(op_jump,
+ int(loop-1) - int(current->size())); // loop back
+ (*current)[exit] = current->size()-exit; // now we know where to jump to (to exit the loop)
+ return true;
+ }
+
+ bool compiler::operator()(ast::return_statement const& x)
+ {
+ if (void_return)
+ {
+ if (x.expr)
+ {
+ std::cout << x.id << std::endl;
+ error_handler(x.id, "'void' function returning a value: ");
+ return false;
+ }
+ }
+ else
+ {
+ if (!x.expr)
+ {
+ std::cout << x.id << std::endl;
+ error_handler(x.id, current_function_name + " function must return a value: ");
+ return false;
+ }
+ }
+
+ if (x.expr)
+ {
+ if (!(*this)(*x.expr))
+ return false;
+ }
+ current->op(op_return);
+ return true;
+ }
+
+ bool compiler::operator()(ast::function const& x)
+ {
+ void_return = x.return_type == "void";
+ if (functions.find(x.function_name.name) != functions.end())
+ {
+ std::cout << x.function_name.id << std::endl;
+ error_handler(x.function_name.id, "Duplicate function: " + x.function_name.name);
+ return false;
+ }
+ boost::shared_ptr<code_gen::function>& p = functions[x.function_name.name];
+ p.reset(new code_gen::function(code, x.args.size()));
+ current = p.get();
+ current_function_name = x.function_name.name;
+
+ // op_stk_adj 0 for now. we'll know how many variables
+ // we'll have later and add them
+ current->op(op_stk_adj, 0);
+ BOOST_FOREACH(ast::identifier const& arg, x.args)
+ {
+ current->add_var(arg.name);
+ }
+
+ if (!(*this)(x.body))
+ return false;
+ (*current)[1] = current->nvars(); // now store the actual number of variables
+ // this includes the arguments
+ return true;
+ }
+
+ bool compiler::operator()(ast::function_list const& x)
+ {
+ // Jump to the main function
+ code.push_back(op_jump);
+ code.push_back(0); // we will fill this in later when we finish compiling
+ // and we know where the main function is
+
+ BOOST_FOREACH(ast::function const& f, x)
+ {
+ if (!(*this)(f))
+ {
+ code.clear();
+ return false;
+ }
+ }
+ // find the main function
+ boost::shared_ptr<code_gen::function> p =
+ find_function("main");
+
+ if (!p) // main function not found
+ {
+ std::cerr << "Error: main function not defined" << std::endl;
+ return false;
+ }
+ code[1] = p->get_address()-1; // jump to this (main function) address
+
+ return true;
+ }
+
+ void compiler::print_assembler() const
+ {
+ typedef std::pair<std::string, boost::shared_ptr<code_gen::function> > pair;
+ BOOST_FOREACH(pair const& p, functions)
+ {
+ std::cout << ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" << std::endl;
+ std::cout << p.second->get_address() << ": function " << p.first << std::endl;
+ p.second->print_assembler();
+ }
+ }
+
+ boost::shared_ptr<code_gen::function>
+ compiler::find_function(std::string const& name) const
+ {
+ function_table::const_iterator i = functions.find(name);
+ if (i == functions.end())
+ return boost::shared_ptr<code_gen::function>();
+ else
+ return i->second;
+ }
+}}
+
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/compiler.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/compiler.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,123 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_CONJURE_COMPILER_HPP)
+#define BOOST_SPIRIT_CONJURE_COMPILER_HPP
+
+#include "ast.hpp"
+#include "error_handler.hpp"
+#include <vector>
+#include <map>
+#include <boost/function.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_function.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+namespace client { namespace code_gen
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // The Function
+ ///////////////////////////////////////////////////////////////////////////
+ struct function
+ {
+ function(std::vector<int>& code, int nargs)
+ : code(code), address(code.size()), size_(0), nargs_(nargs) {}
+
+ void op(int a);
+ void op(int a, int b);
+ void op(int a, int b, int c);
+
+ int& operator[](std::size_t i) { return code[address+i]; }
+ int const& operator[](std::size_t i) const { return code[address+i]; }
+ std::size_t size() const { return size_; }
+ std::size_t get_address() const { return address; }
+
+ int nargs() const { return nargs_; }
+ int nvars() const { return variables.size(); }
+ int const* find_var(std::string const& name) const;
+ void add_var(std::string const& name);
+ void link_to(std::string const& name, std::size_t address);
+
+ void print_assembler() const;
+
+ private:
+
+ std::map<std::string, int> variables;
+ std::map<std::size_t, std::string> function_calls;
+ std::vector<int>& code;
+ std::size_t address;
+ std::size_t size_;
+ std::size_t nargs_;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ // The Compiler
+ ///////////////////////////////////////////////////////////////////////////
+ struct compiler
+ {
+ typedef bool result_type;
+
+ template <typename ErrorHandler>
+ compiler(ErrorHandler& error_handler_)
+ : current(0)
+ {
+ using namespace boost::phoenix::arg_names;
+ namespace phx = boost::phoenix;
+ using boost::phoenix::function;
+
+ error_handler = function<ErrorHandler>(error_handler_)(
+ "Error! ", _2, phx::cref(error_handler_.iters)[_1]);
+ }
+
+ bool operator()(ast::nil) { BOOST_ASSERT(0); return false; }
+ bool operator()(unsigned int x);
+ bool operator()(bool x);
+ bool operator()(ast::identifier const& x);
+ bool operator()(ast::optoken const& x);
+ bool operator()(ast::unary const& x);
+ bool operator()(ast::function_call const& x);
+ bool operator()(ast::expression const& x);
+ bool operator()(ast::assignment const& x);
+ bool operator()(ast::variable_declaration const& x);
+ bool operator()(ast::statement_list const& x);
+ bool operator()(ast::statement const& x);
+ bool operator()(ast::if_statement const& x);
+ bool operator()(ast::while_statement const& x);
+ bool operator()(ast::return_statement const& x);
+ bool operator()(ast::function const& x);
+ bool operator()(ast::function_list const& x);
+
+ void print_assembler() const;
+
+ boost::shared_ptr<code_gen::function>
+ find_function(std::string const& name) const;
+
+ std::vector<int>& get_code() { return code; }
+ std::vector<int> const& get_code() const { return code; }
+
+ private:
+
+ bool compile_expression(
+ int min_precedence,
+ std::list<ast::operation>::const_iterator& rbegin,
+ std::list<ast::operation>::const_iterator rend);
+
+ typedef std::map<std::string, boost::shared_ptr<code_gen::function> > function_table;
+
+ std::vector<int> code;
+ code_gen::function* current;
+ std::string current_function_name;
+ function_table functions;
+ bool void_return;
+
+ boost::function<
+ void(int tag, std::string const& what)>
+ error_handler;
+ };
+}}
+
+#endif
\ No newline at end of file
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/config.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/config.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,51 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_CONJURE_LEXER_CONFIG_HPP)
+#define BOOST_SPIRIT_CONJURE_LEXER_CONFIG_HPP
+
+///////////////////////////////////////////////////////////////////////////////
+// The conjure lexer example can be built in 3 different variations:
+//
+// - With a lexer using runtime generated DFA tables
+// - With a lexer using pre-generated (static) DFA tables
+// - With a lexer using a pre-generated custom switch based state machine
+//
+// Use one of the following preprocessor constants to define, which of those
+// will be built:
+
+///////////////////////////////////////////////////////////////////////////////
+// Use the lexer based on runtime generated DFA tables
+// #define CONJURE_LEXER_DYNAMIC_TABLES 1
+
+///////////////////////////////////////////////////////////////////////////////
+// Use the lexer based on pre-generated static DFA tables
+// #define CONJURE_LEXER_STATIC_TABLES 1
+
+///////////////////////////////////////////////////////////////////////////////
+// Use the lexer based on runtime generated DFA tables
+// #define CONJURE_LEXER_STATIC_SWITCH 1
+
+///////////////////////////////////////////////////////////////////////////////
+// The default is to use the dynamic table driven lexer
+#if CONJURE_LEXER_DYNAMIC_TABLES == 0 && \
+ CONJURE_LEXER_STATIC_TABLES == 0 && \
+ CONJURE_LEXER_STATIC_SWITCH == 0
+
+#define CONJURE_LEXER_DYNAMIC_TABLES 1
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+// Make sure we have only one lexer type selected
+#if (CONJURE_LEXER_DYNAMIC_TABLES != 0 && CONJURE_LEXER_STATIC_TABLES != 0) || \
+ (CONJURE_LEXER_DYNAMIC_TABLES != 0 && CONJURE_LEXER_STATIC_SWITCH != 0) || \
+ (CONJURE_LEXER_STATIC_TABLES != 0 && CONJURE_LEXER_STATIC_SWITCH != 0)
+
+#error "Configuration problem: please select exactly one type of lexer to build"
+#endif
+
+#endif
+
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/conjure_static_lexer.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/conjure_static_lexer.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,484 @@
+// Copyright (c) 2008-2009 Ben Hanson
+// Copyright (c) 2008-2011 Hartmut Kaiser
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// Auto-generated by boost::lexer, do not edit
+
+#if !defined(BOOST_SPIRIT_LEXER_NEXT_TOKEN_CONJURE_STATIC_JUN__4_2011_19_46_16)
+#define BOOST_SPIRIT_LEXER_NEXT_TOKEN_CONJURE_STATIC_JUN__4_2011_19_46_16
+
+#include <boost/detail/iterator.hpp>
+#include <boost/spirit/home/support/detail/lexer/char_traits.hpp>
+
+////////////////////////////////////////////////////////////////////////////////
+// the generated table of state names and the tokenizer have to be
+// defined in the boost::spirit::lex::lexertl::static_ namespace
+namespace boost { namespace spirit { namespace lex { namespace lexertl { namespace static_ {
+
+////////////////////////////////////////////////////////////////////////////////
+// this table defines the names of the lexer states
+char const* const lexer_state_names_conjure_static[1] =
+{
+ "INITIAL"
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// this variable defines the number of lexer states
+std::size_t const lexer_state_count_conjure_static = 1;
+
+////////////////////////////////////////////////////////////////////////////////
+// this function returns the next matched token
+template<typename Iterator>
+std::size_t next_token_conjure_static (std::size_t& /*start_state_*/, bool& /*bol_*/,
+ Iterator &start_token_, Iterator const& end_, std::size_t& unique_id_)
+{
+ enum {end_state_index, id_index, unique_id_index, state_index, bol_index,
+ eol_index, dead_state_index, dfa_offset};
+
+ static std::size_t const npos = static_cast<std::size_t>(~0);
+ static std::size_t const lookup_[256] = {
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 7, 7, 41, 41, 7, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 7, 8, 41, 41, 41, 41, 9, 41,
+ 10, 11, 12, 13, 14, 15, 41, 16,
+ 17, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 41, 19, 20, 21, 22, 41,
+ 41, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 41, 41, 41, 41, 18,
+ 41, 23, 18, 18, 24, 25, 26, 18,
+ 27, 28, 18, 18, 29, 18, 30, 31,
+ 18, 18, 32, 33, 34, 35, 36, 37,
+ 18, 18, 18, 38, 39, 40, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41 };
+ static std::size_t const dfa_alphabet_ = 42;
+ static std::size_t const dfa_[2604] = {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 27, 13, 11, 20, 21, 18, 16,
+ 24, 17, 19, 2, 26, 25, 14, 12,
+ 15, 26, 26, 7, 4, 26, 6, 26,
+ 26, 26, 9, 26, 3, 26, 5, 8,
+ 22, 10, 23, 0,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, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 26, 26, 0, 0, 0,
+ 0, 26, 52, 26, 26, 26, 26, 26,
+ 26, 26, 26, 26, 26, 26, 26, 26,
+ 0, 0, 0, 0, 1, 65640, 3, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 26, 26, 0,
+ 0, 0, 0, 26, 26, 26, 26, 26,
+ 26, 26, 26, 26, 26, 26, 26, 26,
+ 26, 26, 0, 0, 0, 0, 1, 65636,
+ 28, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 26,
+ 26, 0, 0, 0, 0, 26, 26, 53,
+ 26, 26, 26, 26, 26, 26, 26, 26,
+ 26, 26, 26, 26, 0, 0, 0, 0,
+ 1, 65636, 28, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 26, 26, 0, 0, 0, 0, 26,
+ 26, 26, 26, 26, 26, 54, 26, 26,
+ 26, 26, 26, 26, 26, 26, 0, 0,
+ 0, 0, 1, 65636, 28, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 26, 26, 0, 0, 0,
+ 0, 26, 26, 26, 26, 26, 26, 26,
+ 26, 26, 26, 26, 26, 55, 26, 26,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 56, 56, 56, 56, 56,
+ 50, 56, 56, 56, 57, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 1, 65646,
+ 1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 26,
+ 26, 0, 0, 0, 0, 26, 26, 26,
+ 26, 26, 26, 26, 26, 26, 26, 26,
+ 26, 26, 26, 26, 0, 0, 0, 0,
+ 1, 65639, 2, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 26, 26, 0, 0, 0, 0, 26,
+ 26, 26, 26, 26, 26, 26, 26, 26,
+ 26, 26, 26, 26, 26, 26, 0, 0,
+ 0, 0, 1, 65642, 5, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 26, 26, 0, 0, 0,
+ 0, 26, 26, 26, 26, 26, 26, 26,
+ 26, 26, 26, 26, 26, 26, 26, 26,
+ 0, 0, 0, 0, 1, 65636, 28, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 26, 26, 0,
+ 0, 0, 0, 26, 26, 58, 26, 26,
+ 26, 26, 26, 26, 26, 26, 26, 26,
+ 26, 26, 0, 0, 0, 0, 1, 65636,
+ 28, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 26,
+ 26, 0, 0, 0, 0, 26, 26, 26,
+ 26, 26, 26, 26, 26, 26, 59, 26,
+ 26, 26, 26, 26, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 56,
+ 56, 56, 56, 56, 60, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 1, 65637, 29, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 1, 65643, 6, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 26, 26, 0,
+ 0, 0, 0, 26, 26, 26, 26, 26,
+ 26, 26, 26, 26, 26, 26, 26, 26,
+ 26, 26, 0, 0, 0, 0, 1, 65636,
+ 28, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 26,
+ 26, 0, 0, 0, 0, 26, 26, 26,
+ 26, 26, 26, 26, 61, 26, 26, 26,
+ 26, 26, 26, 26, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 56,
+ 56, 56, 56, 56, 60, 56, 56, 56,
+ 57, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 1, 65644, 7, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 26, 26, 0, 0, 0,
+ 0, 26, 26, 26, 26, 26, 26, 26,
+ 26, 26, 26, 26, 26, 26, 26, 26,
+ 0, 0, 0, 0 };
+
+ if (start_token_ == end_)
+ {
+ unique_id_ = npos;
+ return 0;
+ }
+
+ std::size_t const* ptr_ = dfa_ + dfa_alphabet_;
+ Iterator curr_ = start_token_;
+ bool end_state_ = *ptr_ != 0;
+ std::size_t id_ = *(ptr_ + id_index);
+ std::size_t uid_ = *(ptr_ + unique_id_index);
+ Iterator end_token_ = start_token_;
+
+ while (curr_ != end_)
+ {
+ std::size_t const state_ =
+ ptr_[lookup_[static_cast<unsigned char>(*curr_++)]];
+
+ if (state_ == 0) break;
+
+ ptr_ = &dfa_[state_ * dfa_alphabet_];
+
+ if (*ptr_)
+ {
+ end_state_ = true;
+ id_ = *(ptr_ + id_index);
+ uid_ = *(ptr_ + unique_id_index);
+ end_token_ = curr_;
+ }
+ }
+
+ if (end_state_)
+ {
+ // return longest match
+ start_token_ = end_token_;
+ }
+ else
+ {
+ id_ = npos;
+ uid_ = npos;
+ }
+
+ unique_id_ = uid_;
+ return id_;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// this defines a generic accessors for the information above
+struct lexer_conjure_static
+{
+ // version number and feature-set of compatible static lexer engine
+ enum
+ {
+ static_version = 65536,
+ supports_bol = false,
+ supports_eol = false
+ };
+
+ // return the number of lexer states
+ static std::size_t state_count()
+ {
+ return lexer_state_count_conjure_static;
+ }
+
+ // return the name of the lexer state as given by 'idx'
+ static char const* state_name(std::size_t idx)
+ {
+ return lexer_state_names_conjure_static[idx];
+ }
+
+ // return the next matched token
+ template<typename Iterator>
+ static std::size_t next(std::size_t &start_state_, bool& bol_
+ , Iterator &start_token_, Iterator const& end_, std::size_t& unique_id_)
+ {
+ return next_token_conjure_static(start_state_, bol_, start_token_, end_, unique_id_);
+ }
+};
+
+}}}}} // namespace boost::spirit::lex::lexertl::static_
+
+#endif
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/conjure_static_lexer_generate.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/conjure_static_lexer_generate.cpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,43 @@
+// Copyright (c) 2001-2011 Hartmut Kaiser
+//
+// 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 small utility program generates the 2 static lexers, the static table
+// driven and the static switch based lexer.
+
+#include <fstream>
+#include <iostream>
+
+#include "lexer_def.hpp"
+#include <boost/spirit/include/lex_generate_static_lexertl.hpp>
+
+int main()
+{
+ typedef std::string::const_iterator base_iterator_type;
+ typedef client::lexer::conjure_tokens<base_iterator_type> lexer_type;
+
+ lexer_type lexer;
+
+ // first generate the static switch based lexer
+ std::ofstream out_static("conjure_static_switch_lexer.hpp");
+
+ bool result = boost::spirit::lex::lexertl::generate_static_switch(
+ lexer, out_static, "conjure_static_switch");
+ if (!result) {
+ std::cerr << "Failed to generate static switch based lexer\n";
+ return -1;
+ }
+
+ // now generate the static table based lexer
+ std::ofstream out("conjure_static_lexer.hpp");
+ result = boost::spirit::lex::lexertl::generate_static(
+ lexer, out, "conjure_static");
+ if (!result) {
+ std::cerr << "Failed to generate static table based lexer\n";
+ return -1;
+ }
+
+ return 0;
+}
+
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/conjure_static_switch_lexer.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/conjure_static_switch_lexer.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,874 @@
+// Copyright (c) 2008-2009 Ben Hanson
+// Copyright (c) 2008-2011 Hartmut Kaiser
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// Auto-generated by boost::lexer, do not edit
+
+#if !defined(BOOST_SPIRIT_LEXER_NEXT_TOKEN_CONJURE_STATIC_SWITCH_JUN__4_2011_19_46_16)
+#define BOOST_SPIRIT_LEXER_NEXT_TOKEN_CONJURE_STATIC_SWITCH_JUN__4_2011_19_46_16
+
+#include <boost/detail/iterator.hpp>
+#include <boost/spirit/home/support/detail/lexer/char_traits.hpp>
+
+////////////////////////////////////////////////////////////////////////////////
+// the generated table of state names and the tokenizer have to be
+// defined in the boost::spirit::lex::lexertl::static_ namespace
+namespace boost { namespace spirit { namespace lex { namespace lexertl { namespace static_ {
+
+////////////////////////////////////////////////////////////////////////////////
+// this table defines the names of the lexer states
+char const* const lexer_state_names_conjure_static_switch[1] =
+{
+ "INITIAL"
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// this variable defines the number of lexer states
+std::size_t const lexer_state_count_conjure_static_switch = 1;
+
+////////////////////////////////////////////////////////////////////////////////
+// this function returns the next matched token
+template<typename Iterator>
+std::size_t next_token_conjure_static_switch (std::size_t& /*start_state_*/, bool& /*bol_*/,
+ Iterator &start_token_, Iterator const& end_, std::size_t& unique_id_)
+{
+ static std::size_t const npos = static_cast<std::size_t>(~0);
+
+ if (start_token_ == end_)
+ {
+ unique_id_ = npos;
+ return 0;
+ }
+
+ Iterator curr_ = start_token_;
+ bool end_state_ = false;
+ std::size_t id_ = npos;
+ std::size_t uid_ = npos;
+ Iterator end_token_ = start_token_;
+
+ char ch_ = 0;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9')) goto state0_1;
+
+ if (ch_ == 't') goto state0_2;
+
+ if (ch_ == 'f') goto state0_3;
+
+ if (ch_ == 'v') goto state0_4;
+
+ if (ch_ == 'i') goto state0_5;
+
+ if (ch_ == 'e') goto state0_6;
+
+ if (ch_ == 'w') goto state0_7;
+
+ if (ch_ == 'r') goto state0_8;
+
+ if (ch_ == '|') goto state0_9;
+
+ if (ch_ == '&') goto state0_10;
+
+ if (ch_ == '=') goto state0_11;
+
+ if (ch_ == '!') goto state0_12;
+
+ if (ch_ == '<') goto state0_13;
+
+ if (ch_ == '>') goto state0_14;
+
+ if (ch_ == '+') goto state0_15;
+
+ if (ch_ == '-') goto state0_16;
+
+ if (ch_ == '*') goto state0_17;
+
+ if (ch_ == '/') goto state0_18;
+
+ if (ch_ == '(') goto state0_19;
+
+ if (ch_ == ')') goto state0_20;
+
+ if (ch_ == '{') goto state0_21;
+
+ if (ch_ == '}') goto state0_22;
+
+ if (ch_ == ',') goto state0_23;
+
+ if (ch_ == ';') goto state0_24;
+
+ if ((ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'd') || (ch_ >= 'g' && ch_ <= 'h') || (ch_ >= 'j' && ch_ <= 'q') || ch_ == 's' || ch_ == 'u' || (ch_ >= 'x' && ch_ <= 'z')) goto state0_25;
+
+ if ((ch_ >= '\t' && ch_ <= '\n') || ch_ == '\r' || ch_ == ' ') goto state0_26;
+ goto end;
+
+state0_1:
+ end_state_ = true;
+ id_ = 65645;
+ uid_ = 0;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9')) goto state0_1;
+ goto end;
+
+state0_2:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'q') || (ch_ >= 's' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'r') goto state0_27;
+ goto end;
+
+state0_3:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'b' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'a') goto state0_28;
+ goto end;
+
+state0_4:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'n') || (ch_ >= 'p' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'o') goto state0_29;
+ goto end;
+
+state0_5:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'e') || (ch_ >= 'g' && ch_ <= 'm') || (ch_ >= 'o' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'n') goto state0_30;
+
+ if (ch_ == 'f') goto state0_31;
+ goto end;
+
+state0_6:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'k') || (ch_ >= 'm' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'l') goto state0_32;
+ goto end;
+
+state0_7:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'g') || (ch_ >= 'i' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'h') goto state0_33;
+ goto end;
+
+state0_8:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'd') || (ch_ >= 'f' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'e') goto state0_34;
+ goto end;
+
+state0_9:
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if (ch_ == '|') goto state0_35;
+ goto end;
+
+state0_10:
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if (ch_ == '&') goto state0_36;
+ goto end;
+
+state0_11:
+ end_state_ = true;
+ id_ = 61;
+ uid_ = 26;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if (ch_ == '=') goto state0_37;
+ goto end;
+
+state0_12:
+ end_state_ = true;
+ id_ = 327715;
+ uid_ = 20;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if (ch_ == '=') goto state0_38;
+ goto end;
+
+state0_13:
+ end_state_ = true;
+ id_ = 196627;
+ uid_ = 12;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if (ch_ == '=') goto state0_39;
+ goto end;
+
+state0_14:
+ end_state_ = true;
+ id_ = 196629;
+ uid_ = 14;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if (ch_ == '=') goto state0_40;
+ goto end;
+
+state0_15:
+ end_state_ = true;
+ id_ = 458777;
+ uid_ = 16;
+ end_token_ = curr_;
+ goto end;
+
+state0_16:
+ end_state_ = true;
+ id_ = 458778;
+ uid_ = 17;
+ end_token_ = curr_;
+ goto end;
+
+state0_17:
+ end_state_ = true;
+ id_ = 196635;
+ uid_ = 18;
+ end_token_ = curr_;
+ goto end;
+
+state0_18:
+ end_state_ = true;
+ id_ = 196636;
+ uid_ = 19;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if (ch_ == '*') goto state0_41;
+ goto end;
+
+state0_19:
+ end_state_ = true;
+ id_ = 40;
+ uid_ = 21;
+ end_token_ = curr_;
+ goto end;
+
+state0_20:
+ end_state_ = true;
+ id_ = 41;
+ uid_ = 22;
+ end_token_ = curr_;
+ goto end;
+
+state0_21:
+ end_state_ = true;
+ id_ = 123;
+ uid_ = 23;
+ end_token_ = curr_;
+ goto end;
+
+state0_22:
+ end_state_ = true;
+ id_ = 125;
+ uid_ = 24;
+ end_token_ = curr_;
+ goto end;
+
+state0_23:
+ end_state_ = true;
+ id_ = 44;
+ uid_ = 25;
+ end_token_ = curr_;
+ goto end;
+
+state0_24:
+ end_state_ = true;
+ id_ = 59;
+ uid_ = 27;
+ end_token_ = curr_;
+ goto end;
+
+state0_25:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'z')) goto state0_25;
+ goto end;
+
+state0_26:
+ end_state_ = true;
+ id_ = 65638;
+ uid_ = 30;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '\t' && ch_ <= '\n') || ch_ == '\r' || ch_ == ' ') goto state0_26;
+ goto end;
+
+state0_27:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 't') || (ch_ >= 'v' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'u') goto state0_42;
+ goto end;
+
+state0_28:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'k') || (ch_ >= 'm' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'l') goto state0_43;
+ goto end;
+
+state0_29:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'h') || (ch_ >= 'j' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'i') goto state0_44;
+ goto end;
+
+state0_30:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 's') || (ch_ >= 'u' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 't') goto state0_45;
+ goto end;
+
+state0_31:
+ end_state_ = true;
+ id_ = 65641;
+ uid_ = 4;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'z')) goto state0_25;
+ goto end;
+
+state0_32:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'r') || (ch_ >= 't' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 's') goto state0_46;
+ goto end;
+
+state0_33:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'h') || (ch_ >= 'j' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'i') goto state0_47;
+ goto end;
+
+state0_34:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 's') || (ch_ >= 'u' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 't') goto state0_48;
+ goto end;
+
+state0_35:
+ end_state_ = true;
+ id_ = 196620;
+ uid_ = 8;
+ end_token_ = curr_;
+ goto end;
+
+state0_36:
+ end_state_ = true;
+ id_ = 196621;
+ uid_ = 9;
+ end_token_ = curr_;
+ goto end;
+
+state0_37:
+ end_state_ = true;
+ id_ = 196625;
+ uid_ = 10;
+ end_token_ = curr_;
+ goto end;
+
+state0_38:
+ end_state_ = true;
+ id_ = 196626;
+ uid_ = 11;
+ end_token_ = curr_;
+ goto end;
+
+state0_39:
+ end_state_ = true;
+ id_ = 196628;
+ uid_ = 13;
+ end_token_ = curr_;
+ goto end;
+
+state0_40:
+ end_state_ = true;
+ id_ = 196630;
+ uid_ = 15;
+ end_token_ = curr_;
+ goto end;
+
+state0_41:
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if (ch_ != '*') goto state0_41;
+
+ if (ch_ == '*') goto state0_49;
+ goto end;
+
+state0_42:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'd') || (ch_ >= 'f' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'e') goto state0_50;
+ goto end;
+
+state0_43:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'r') || (ch_ >= 't' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 's') goto state0_42;
+ goto end;
+
+state0_44:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'c') || (ch_ >= 'e' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'd') goto state0_51;
+ goto end;
+
+state0_45:
+ end_state_ = true;
+ id_ = 65640;
+ uid_ = 3;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'z')) goto state0_25;
+ goto end;
+
+state0_46:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'd') || (ch_ >= 'f' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'e') goto state0_52;
+ goto end;
+
+state0_47:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'k') || (ch_ >= 'm' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'l') goto state0_53;
+ goto end;
+
+state0_48:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 't') || (ch_ >= 'v' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'u') goto state0_54;
+ goto end;
+
+state0_49:
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if (ch_ == '*') goto state0_49;
+
+ if (ch_ != '*' && ch_ != '/') goto state0_55;
+
+ if (ch_ == '/') goto state0_56;
+ goto end;
+
+state0_50:
+ end_state_ = true;
+ id_ = 65646;
+ uid_ = 1;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'z')) goto state0_25;
+ goto end;
+
+state0_51:
+ end_state_ = true;
+ id_ = 65639;
+ uid_ = 2;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'z')) goto state0_25;
+ goto end;
+
+state0_52:
+ end_state_ = true;
+ id_ = 65642;
+ uid_ = 5;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'z')) goto state0_25;
+ goto end;
+
+state0_53:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'd') || (ch_ >= 'f' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'e') goto state0_57;
+ goto end;
+
+state0_54:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'q') || (ch_ >= 's' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'r') goto state0_58;
+ goto end;
+
+state0_55:
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if (ch_ != '*') goto state0_55;
+
+ if (ch_ == '*') goto state0_59;
+ goto end;
+
+state0_56:
+ end_state_ = true;
+ id_ = 65637;
+ uid_ = 29;
+ end_token_ = curr_;
+ goto end;
+
+state0_57:
+ end_state_ = true;
+ id_ = 65643;
+ uid_ = 6;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'z')) goto state0_25;
+ goto end;
+
+state0_58:
+ end_state_ = true;
+ id_ = 65636;
+ uid_ = 28;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'm') || (ch_ >= 'o' && ch_ <= 'z')) goto state0_25;
+
+ if (ch_ == 'n') goto state0_60;
+ goto end;
+
+state0_59:
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if (ch_ != '*' && ch_ != '/') goto state0_55;
+
+ if (ch_ == '/') goto state0_56;
+
+ if (ch_ == '*') goto state0_59;
+ goto end;
+
+state0_60:
+ end_state_ = true;
+ id_ = 65644;
+ uid_ = 7;
+ end_token_ = curr_;
+
+ if (curr_ == end_) goto end;
+ ch_ = *curr_;
+ ++curr_;
+
+ if ((ch_ >= '0' && ch_ <= '9') || (ch_ >= 'A' && ch_ <= 'Z') || ch_ == '_' || (ch_ >= 'a' && ch_ <= 'z')) goto state0_25;
+
+end:
+ if (end_state_)
+ {
+ // return longest match
+ start_token_ = end_token_;
+ }
+ else
+ {
+ id_ = npos;
+ uid_ = npos;
+ }
+
+ unique_id_ = uid_;
+ return id_;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// this defines a generic accessors for the information above
+struct lexer_conjure_static_switch
+{
+ // version number and feature-set of compatible static lexer engine
+ enum
+ {
+ static_version = 65536,
+ supports_bol = false,
+ supports_eol = false
+ };
+
+ // return the number of lexer states
+ static std::size_t state_count()
+ {
+ return lexer_state_count_conjure_static_switch;
+ }
+
+ // return the name of the lexer state as given by 'idx'
+ static char const* state_name(std::size_t idx)
+ {
+ return lexer_state_names_conjure_static_switch[idx];
+ }
+
+ // return the next matched token
+ template<typename Iterator>
+ static std::size_t next(std::size_t &start_state_, bool& bol_
+ , Iterator &start_token_, Iterator const& end_, std::size_t& unique_id_)
+ {
+ return next_token_conjure_static_switch(start_state_, bol_, start_token_, end_, unique_id_);
+ }
+};
+
+}}}}} // namespace boost::spirit::lex::lexertl::static_
+
+#endif
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/error_handler.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/error_handler.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,97 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_CONJURE_ERROR_HANDLER_HPP)
+#define BOOST_SPIRIT_CONJURE_ERROR_HANDLER_HPP
+
+#include <iostream>
+#include <string>
+#include <vector>
+
+namespace client
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // The error handler
+ ///////////////////////////////////////////////////////////////////////////////
+ template <typename BaseIterator, typename Iterator>
+ struct error_handler
+ {
+ template <typename, typename, typename>
+ struct result { typedef void type; };
+
+ error_handler(BaseIterator first, BaseIterator last)
+ : first(first), last(last) {}
+
+ template <typename Message, typename What>
+ void operator()(
+ Message const& message,
+ What const& what,
+ Iterator err_pos) const
+ {
+ // retrieve underlying iterator from current token
+ BaseIterator err_pos_base = err_pos->matched().begin();
+
+ int line;
+ BaseIterator line_start = get_pos(err_pos_base, line);
+ if (err_pos_base != last)
+ {
+ std::cout << message << what << " line " << line << ':' << std::endl;
+ std::cout << get_line(line_start) << std::endl;
+ for (; line_start != err_pos_base; ++line_start)
+ std::cout << ' ';
+ std::cout << '^' << std::endl;
+ }
+ else
+ {
+ std::cout << "Unexpected end of file. ";
+ std::cout << message << what << " line " << line << std::endl;
+ }
+ }
+
+ BaseIterator get_pos(BaseIterator err_pos, int& line) const
+ {
+ line = 1;
+ BaseIterator i = first;
+ BaseIterator line_start = first;
+ while (i != err_pos)
+ {
+ bool eol = false;
+ if (i != err_pos && *i == '\r') // CR
+ {
+ eol = true;
+ line_start = ++i;
+ }
+ if (i != err_pos && *i == '\n') // LF
+ {
+ eol = true;
+ line_start = ++i;
+ }
+ if (eol)
+ ++line;
+ else
+ ++i;
+ }
+ return line_start;
+ }
+
+ std::string get_line(BaseIterator err_pos) const
+ {
+ BaseIterator i = err_pos;
+ // position i to the next EOL
+ while (i != last && (*i != '\r' && *i != '\n'))
+ ++i;
+ return std::string(err_pos, i);
+ }
+
+ BaseIterator first;
+ BaseIterator last;
+ std::vector<Iterator> iters;
+ };
+}
+
+#endif
+
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/expression.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/expression.cpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,20 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+#if defined(_MSC_VER)
+# pragma warning(disable: 4345)
+#endif
+
+#include "config.hpp"
+#include "lexer.hpp"
+#include "expression_def.hpp"
+
+typedef std::string::const_iterator base_iterator_type;
+typedef client::lexer::conjure_tokens<base_iterator_type> lexer_type;
+typedef lexer_type::iterator_type iterator_type;
+
+template struct client::parser::expression<iterator_type, lexer_type>;
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/expression.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/expression.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,58 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_CONJURE_EXPRESSION_HPP)
+#define BOOST_SPIRIT_CONJURE_EXPRESSION_HPP
+
+///////////////////////////////////////////////////////////////////////////////
+// Spirit v2.5 allows you to suppress automatic generation
+// of predefined terminals to speed up complation. With
+// BOOST_SPIRIT_NO_PREDEFINED_TERMINALS defined, you are
+// responsible in creating instances of the terminals that
+// you need (e.g. see qi::uint_type uint_ below).
+#define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
+///////////////////////////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////////
+// Uncomment this if you want to enable debugging
+// #define BOOST_SPIRIT_QI_DEBUG
+///////////////////////////////////////////////////////////////////////////////
+
+#include <boost/spirit/include/qi.hpp>
+#include "ast.hpp"
+#include "error_handler.hpp"
+#include <vector>
+
+namespace client { namespace parser
+{
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // The expression grammar
+ ///////////////////////////////////////////////////////////////////////////////
+ template <typename Iterator, typename Lexer>
+ struct expression : qi::grammar<Iterator, ast::expression()>
+ {
+ typedef error_handler<typename Lexer::base_iterator_type, Iterator>
+ error_handler_type;
+
+ expression(error_handler_type& error_handler, Lexer const& l);
+
+ Lexer const& lexer;
+
+ qi::rule<Iterator, ast::expression()> expr;
+ qi::rule<Iterator, ast::operand()> unary_expr, primary_expr;
+ qi::rule<Iterator, ast::function_call()> function_call;
+ qi::rule<Iterator, std::list<ast::expression>()> argument_list;
+ qi::rule<Iterator, std::string()> identifier;
+ };
+}}
+
+#endif
+
+
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/expression_def.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/expression_def.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,94 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+#include "expression.hpp"
+#include "error_handler.hpp"
+#include "annotation.hpp"
+#include <boost/spirit/include/phoenix_function.hpp>
+#include <boost/spirit/include/lex_plain_token.hpp>
+
+namespace client { namespace parser
+{
+ template <typename Iterator, typename Lexer>
+ expression<Iterator, Lexer>::expression(
+ error_handler<typename Lexer::base_iterator_type, Iterator>& error_handler
+ , Lexer const& l)
+ : expression::base_type(expr), lexer(l)
+ {
+ qi::_1_type _1;
+ qi::_2_type _2;
+ qi::_3_type _3;
+ qi::_4_type _4;
+
+ qi::_val_type _val;
+ qi::tokenid_mask_type tokenid_mask;
+
+ using qi::on_error;
+ using qi::on_success;
+ using qi::fail;
+ using boost::phoenix::function;
+
+ typedef client::error_handler<typename Lexer::base_iterator_type, Iterator>
+ error_handler_type;
+ typedef function<error_handler_type> error_handler_function;
+ typedef function<client::annotation<Iterator> > annotation_function;
+
+ ///////////////////////////////////////////////////////////////////////
+ // Main expression grammar
+ expr =
+ unary_expr
+ >> *(tokenid_mask(ast::op_binary) > unary_expr)
+ ;
+
+ unary_expr =
+ primary_expr
+ | (tokenid_mask(ast::op_unary) > primary_expr)
+ ;
+
+ primary_expr =
+ lexer.uint_
+ | function_call
+ | identifier
+ | lexer.bool_
+ | '(' > expr > ')'
+ ;
+
+ function_call =
+ (identifier >> '(')
+ > argument_list
+ > ')'
+ ;
+
+ argument_list = -(expr % ',');
+
+ identifier = lexer.identifier;
+
+ ///////////////////////////////////////////////////////////////////////
+ // Debugging and error handling and reporting support.
+ BOOST_SPIRIT_DEBUG_NODES(
+ (expr)
+ (unary_expr)
+ (primary_expr)
+ (function_call)
+ (argument_list)
+ (identifier)
+ );
+
+ ///////////////////////////////////////////////////////////////////////
+ // Error handling: on error in expr, call error_handler.
+ on_error<fail>(expr,
+ error_handler_function(error_handler)(
+ "Error! Expecting ", _4, _3));
+
+ ///////////////////////////////////////////////////////////////////////
+ // Annotation: on success in primary_expr, call annotation.
+ on_success(primary_expr,
+ annotation_function(error_handler.iters)(_val, _1));
+ }
+}}
+
+
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/function.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/function.cpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,20 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+#if defined(_MSC_VER)
+# pragma warning(disable: 4345)
+#endif
+
+#include "config.hpp"
+#include "lexer.hpp"
+#include "function_def.hpp"
+
+typedef std::string::const_iterator base_iterator_type;
+typedef client::lexer::conjure_tokens<base_iterator_type> lexer_type;
+typedef lexer_type::iterator_type iterator_type;
+
+template struct client::parser::function<iterator_type, lexer_type>;
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/function.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/function.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,36 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_CONJURE_FUNCTION_HPP)
+#define BOOST_SPIRIT_CONJURE_FUNCTION_HPP
+
+#include "statement.hpp"
+
+namespace client { namespace parser
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // The function grammar
+ ///////////////////////////////////////////////////////////////////////////////
+ template <typename Iterator, typename Lexer>
+ struct function : qi::grammar<Iterator, ast::function()>
+ {
+ typedef error_handler<typename Lexer::base_iterator_type, Iterator>
+ error_handler_type;
+
+ function(error_handler_type& error_handler, Lexer const& l);
+
+ statement<Iterator, Lexer> body;
+
+ qi::rule<Iterator, ast::identifier()> identifier;
+ qi::rule<Iterator, std::list<ast::identifier>()> argument_list;
+ qi::rule<Iterator, ast::function()> start;
+ };
+}}
+
+#endif
+
+
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/function_def.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/function_def.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,66 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+#include "token_ids.hpp"
+#include "function.hpp"
+#include "error_handler.hpp"
+#include "annotation.hpp"
+
+namespace client { namespace parser
+{
+ template <typename Iterator, typename Lexer>
+ function<Iterator, Lexer>::function(
+ error_handler<typename Lexer::base_iterator_type, Iterator>& error_handler
+ , Lexer const& l)
+ : function::base_type(start), body(error_handler, l)
+ {
+ qi::_1_type _1;
+ qi::_2_type _2;
+ qi::_3_type _3;
+ qi::_4_type _4;
+
+ qi::_val_type _val;
+ qi::token_type token;
+
+ using qi::on_error;
+ using qi::on_success;
+ using qi::fail;
+ using boost::phoenix::function;
+
+ typedef client::error_handler<typename Lexer::base_iterator_type, Iterator>
+ error_handler_type;
+ typedef function<error_handler_type> error_handler_function;
+ typedef function<client::annotation<Iterator> > annotation_function;
+
+ identifier = body.expr.identifier;
+ argument_list = -(identifier % ',');
+
+ start = (token(lexer::ID_VOID_KWD) | token(lexer::ID_INT_KWD))
+ > identifier
+ > '(' > argument_list > ')'
+ > '{' > body > '}'
+ ;
+
+ // Debugging and error handling and reporting support.
+ BOOST_SPIRIT_DEBUG_NODES(
+ (identifier)
+ (argument_list)
+ (start)
+ );
+
+ // Error handling: on error in start, call error_handler.
+ on_error<fail>(start,
+ error_handler_function(error_handler)(
+ "Error! Expecting ", _4, _3));
+
+ // Annotation: on success in start, call annotation.
+ on_success(identifier,
+ annotation_function(error_handler.iters)(_val, _1));
+ }
+}}
+
+
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/lexer.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/lexer.cpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,15 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+#if defined(_MSC_VER)
+# pragma warning(disable: 4345)
+#endif
+
+#include "config.hpp"
+#include "lexer_def.hpp"
+
+typedef std::string::const_iterator base_iterator_type;
+template client::lexer::conjure_tokens<base_iterator_type>::conjure_tokens();
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/lexer.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/lexer.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,82 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_CONJURE_LEXER_HPP)
+#define BOOST_SPIRIT_CONJURE_LEXER_HPP
+
+#include "config.hpp"
+#include "token_ids.hpp"
+
+#if CONJURE_LEXER_STATIC_TABLES != 0
+#include <boost/spirit/include/lex_static_lexertl.hpp>
+#include "conjure_static_lexer.hpp"
+#elif CONJURE_LEXER_STATIC_SWITCH != 0
+#include <boost/spirit/include/lex_static_lexertl.hpp>
+#include "conjure_static_switch_lexer.hpp"
+#endif
+
+namespace client { namespace lexer
+{
+ ///////////////////////////////////////////////////////////////////////////
+ namespace detail
+ {
+ namespace lex = boost::spirit::lex;
+
+ template <typename BaseIterator>
+ struct get_lexer_type
+ {
+ // Our token needs to be able to carry several token values:
+ // std::string, unsigned int, and bool
+ typedef boost::mpl::vector<std::string, unsigned int, bool>
+ token_value_types;
+
+ // Using the position_token class as the token type to be returned
+ // from the lexer iterators allows to retain positional information
+ // as every token instance stores an iterator pair pointing to the
+ // matched input sequence.
+ typedef lex::lexertl::position_token<
+ BaseIterator, token_value_types, boost::mpl::false_
+ > token_type;
+
+#if CONJURE_LEXER_DYNAMIC_TABLES != 0
+ // use the lexer based on runtime generated DFA tables
+ typedef lex::lexertl::actor_lexer<token_type> type;
+#elif CONJURE_LEXER_STATIC_TABLES != 0
+ // use the lexer based on pre-generated static DFA tables
+ typedef lex::lexertl::static_actor_lexer<
+ token_type
+ , boost::spirit::lex::lexertl::static_::lexer_conjure_static
+ > type;
+#elif CONJURE_LEXER_STATIC_SWITCH != 0
+ // use the lexer based on pre-generated static code
+ typedef lex::lexertl::static_actor_lexer<
+ token_type
+ , boost::spirit::lex::lexertl::static_::lexer_conjure_static_switch
+ > type;
+#else
+#error "Configuration problem: please select exactly one type of lexer to build"
+#endif
+ };
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename BaseIterator>
+ struct conjure_tokens
+ : lex::lexer<typename detail::get_lexer_type<BaseIterator>::type>
+ {
+ typedef BaseIterator base_iterator_type;
+
+ conjure_tokens();
+
+ lex::token_def<std::string> identifier;
+ lex::token_def<unsigned int> uint_;
+ lex::token_def<bool> bool_;
+ };
+}}
+
+#endif
+
+
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/lexer_def.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/lexer_def.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,62 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+
+#include "lexer.hpp"
+
+namespace client { namespace lexer
+{
+ template <typename BaseIterator>
+ conjure_tokens<BaseIterator>::conjure_tokens()
+ : identifier("[a-zA-Z_][a-zA-Z_0-9]*", ID_IDENTIFIER)
+ , uint_("[0-9]+", ID_UINT)
+ , bool_("true|false", ID_BOOL)
+ {
+ lex::_pass_type _pass;
+
+ this->self = uint_ | bool_;
+
+ this->self.add
+ ("void", ID_VOID_KWD)
+ ("int", ID_INT_KWD)
+ ("if", ID_IF_KWD)
+ ("else", ID_ELSE_KWD)
+ ("while", ID_WHILE_KWD)
+ ("return", ID_RETURN_KWD)
+ ;
+
+ this->self.add
+ ("\\|\\|", ID_OP_LOGICAL_OR)
+ ("&&", ID_OP_LOGICAL_AND)
+ ("==", ID_OP_EQUAL)
+ ("!=", ID_OP_NOT_EQUAL)
+ ("<", ID_OP_LESS)
+ ("<=", ID_OP_LESS_EQUAL)
+ (">", ID_OP_GREATER)
+ (">=", ID_OP_GREATER_EQUAL)
+ ("\\+", ID_OP_PLUS)
+ ("\\-", ID_OP_MINUS)
+ ("\\*", ID_OP_TIMES)
+ ("\\/", ID_OP_DIVIDE)
+ ("!", ID_OP_NOT)
+ ;
+
+ this->self += lex::char_('(') | ')' | '{' | '}' | ',' | '=' | ';';
+
+ this->self +=
+ identifier
+ | lex::string("\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/", ID_COMMENT)
+ [
+ lex::_pass = lex::pass_flags::pass_ignore
+ ]
+ | lex::string("[ \t\n\r]+", ID_WHITESPACE)
+ [
+ lex::_pass = lex::pass_flags::pass_ignore
+ ]
+ ;
+ }
+}}
+
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/main.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/main.cpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,134 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+///////////////////////////////////////////////////////////////////////////////
+//
+// Not a calculator anymore, right? :-)
+//
+// [ JDG April 10, 2007 ] spirit2
+// [ JDG February 18, 2011 ] Pure attributes. No semantic actions.
+// [ HK June 3, 2011 ] Adding lexer
+//
+///////////////////////////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////////
+// Define this to enable debugging
+//#define BOOST_SPIRIT_QI_DEBUG
+
+#include "config.hpp"
+#include "function.hpp"
+#include "vm.hpp"
+#include "compiler.hpp"
+#include "lexer.hpp"
+#include <boost/lexical_cast.hpp>
+#include <fstream>
+
+///////////////////////////////////////////////////////////////////////////////
+// Main program
+///////////////////////////////////////////////////////////////////////////////
+int main(int argc, char **argv)
+{
+ char const* filename;
+ if (argc > 1)
+ {
+ filename = argv[1];
+ }
+ else
+ {
+ std::cerr << "Error: No input file provided." << std::endl;
+ return 1;
+ }
+
+ std::ifstream in(filename, std::ios_base::in);
+
+ if (!in)
+ {
+ std::cerr << "Error: Could not open input file: "
+ << filename << std::endl;
+ return 1;
+ }
+
+ std::string source_code; // We will read the contents here.
+ in.unsetf(std::ios::skipws); // No white space skipping!
+ std::copy(
+ std::istream_iterator<char>(in),
+ std::istream_iterator<char>(),
+ std::back_inserter(source_code));
+
+ typedef std::string::const_iterator base_iterator_type;
+ typedef client::lexer::conjure_tokens<base_iterator_type> lexer_type;
+ typedef lexer_type::iterator_type iterator_type;
+
+ lexer_type lexer; // Our lexer
+
+ base_iterator_type first = source_code.begin();
+ base_iterator_type last = source_code.end();
+
+ iterator_type iter = lexer.begin(first, last);
+ iterator_type end = lexer.end();
+
+ client::vmachine vm; // Our virtual machine
+ client::ast::function_list ast; // Our AST
+
+ client::error_handler<base_iterator_type, iterator_type>
+ error_handler(first, last); // Our error handler
+ client::parser::function<iterator_type, lexer_type>
+ function(error_handler, lexer); // Our parser
+ client::code_gen::compiler
+ compiler(error_handler); // Our compiler
+
+ // note: we don't need a skipper
+ bool success = parse(iter, end, +function, ast);
+
+ std::cout << "-------------------------\n";
+
+ if (success && iter == end)
+ {
+ if (compiler(ast))
+ {
+ boost::shared_ptr<client::code_gen::function>
+ p = compiler.find_function("main");
+ if (!p)
+ return 1;
+
+ int nargs = argc-2;
+ if (p->nargs() != nargs)
+ {
+ std::cerr << "Error: main function requires " << p->nargs() << " arguments." << std::endl;
+ std::cerr << nargs << " supplied." << std::endl;
+ return 1;
+ }
+
+ std::cout << "Success\n";
+ std::cout << "-------------------------\n";
+ std::cout << "Assembler----------------\n\n";
+ compiler.print_assembler();
+
+ // Push the arguments into our stack
+ for (int i = 0; i < nargs; ++i)
+ vm.get_stack()[i] = boost::lexical_cast<int>(argv[i+2]);
+
+ // Call the interpreter
+ int r = vm.execute(compiler.get_code());
+
+ std::cout << "-------------------------\n";
+ std::cout << "Result: " << r << std::endl;
+ std::cout << "-------------------------\n\n";
+ }
+ else
+ {
+ std::cout << "Compile failure\n";
+ }
+ }
+ else
+ {
+ std::cout << "Parse failure\n";
+ }
+ return 0;
+}
+
+
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/statement.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/statement.cpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,20 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+#if defined(_MSC_VER)
+# pragma warning(disable: 4345)
+#endif
+
+#include "config.hpp"
+#include "lexer.hpp"
+#include "statement_def.hpp"
+
+typedef std::string::const_iterator base_iterator_type;
+typedef client::lexer::conjure_tokens<base_iterator_type> lexer_type;
+typedef lexer_type::iterator_type iterator_type;
+
+template struct client::parser::statement<iterator_type, lexer_type>;
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/statement.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/statement.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,42 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_CONJURE_STATEMENT_HPP)
+#define BOOST_SPIRIT_CONJURE_STATEMENT_HPP
+
+#include "expression.hpp"
+
+namespace client { namespace parser
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // The statement grammar
+ ///////////////////////////////////////////////////////////////////////////////
+ template <typename Iterator, typename Lexer>
+ struct statement : qi::grammar<Iterator, ast::statement_list()>
+ {
+ typedef error_handler<typename Lexer::base_iterator_type, Iterator>
+ error_handler_type;
+
+ statement(error_handler_type& error_handler, Lexer const& l);
+
+ expression<Iterator, Lexer> expr;
+
+ qi::rule<Iterator, ast::statement_list()>
+ statement_list, compound_statement;
+
+ qi::rule<Iterator, ast::statement()> statement_;
+ qi::rule<Iterator, ast::variable_declaration()> variable_declaration;
+ qi::rule<Iterator, ast::assignment()> assignment;
+ qi::rule<Iterator, ast::if_statement()> if_statement;
+ qi::rule<Iterator, ast::while_statement()> while_statement;
+ qi::rule<Iterator, ast::return_statement()> return_statement;
+ };
+}}
+
+#endif
+
+
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/statement_def.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/statement_def.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,117 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+#include "token_ids.hpp"
+#include "statement.hpp"
+#include "error_handler.hpp"
+#include "annotation.hpp"
+
+namespace client { namespace parser
+{
+ template <typename Iterator, typename Lexer>
+ statement<Iterator, Lexer>::statement(
+ error_handler<typename Lexer::base_iterator_type, Iterator>& error_handler
+ , Lexer const& l)
+ : statement::base_type(statement_list), expr(error_handler, l)
+ {
+ qi::_1_type _1;
+ qi::_2_type _2;
+ qi::_3_type _3;
+ qi::_4_type _4;
+
+ qi::_val_type _val;
+ qi::raw_token_type raw_token;
+
+ using qi::on_error;
+ using qi::on_success;
+ using qi::fail;
+ using boost::phoenix::function;
+
+ typedef client::error_handler<typename Lexer::base_iterator_type, Iterator>
+ error_handler_type;
+ typedef function<error_handler_type> error_handler_function;
+ typedef function<client::annotation<Iterator> > annotation_function;
+
+ statement_list =
+ +statement_
+ ;
+
+ statement_ =
+ variable_declaration
+ | assignment
+ | compound_statement
+ | if_statement
+ | while_statement
+ | return_statement
+ ;
+
+ variable_declaration =
+ raw_token(lexer::ID_INT_KWD)
+ > expr.identifier
+ > -('=' > expr)
+ > ';'
+ ;
+
+ assignment =
+ expr.identifier
+ > '='
+ > expr
+ > ';'
+ ;
+
+ if_statement =
+ raw_token(lexer::ID_IF_KWD)
+ > '('
+ > expr
+ > ')'
+ > statement_
+ >
+ -(
+ raw_token(lexer::ID_ELSE_KWD)
+ > statement_
+ )
+ ;
+
+ while_statement =
+ raw_token(lexer::ID_WHILE_KWD)
+ > '('
+ > expr
+ > ')'
+ > statement_
+ ;
+
+ compound_statement =
+ '{' >> -statement_list >> '}'
+ ;
+
+ return_statement =
+ raw_token(lexer::ID_RETURN_KWD)
+ > -expr
+ > ';'
+ ;
+
+ // Debugging and error handling and reporting support.
+ BOOST_SPIRIT_DEBUG_NODES(
+ (statement_list)
+ (variable_declaration)
+ (assignment)
+ );
+
+ // Error handling: on error in statement_list, call error_handler.
+ on_error<fail>(statement_list,
+ error_handler_function(error_handler)(
+ "Error! Expecting ", _4, _3));
+
+ // Annotation: on success in assignment, call annotation.
+ on_success(assignment,
+ annotation_function(error_handler.iters)(_val, _1));
+ on_success(return_statement,
+ annotation_function(error_handler.iters)(_val, _1));
+ }
+}}
+
+
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/token_ids.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/token_ids.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,55 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Hartmut Kaiser
+
+ 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_CONJURE_TOKEN_IDS_HPP)
+#define BOOST_SPIRIT_CONJURE_TOKEN_IDS_HPP
+
+#include <boost/spirit/include/lex_lexertl.hpp>
+#include <boost/spirit/include/lex_lexertl_position_token.hpp>
+
+namespace client { namespace lexer
+{
+ namespace lex = boost::spirit::lex;
+
+ enum tokenids
+ {
+ ID_OP_OPERATOR = 0x10000,
+ ID_OP_BINARY = 0x20000,
+ ID_OP_UNARY = 0x40000,
+
+ // the token ids (added values below) have to correspond to the
+ // sequence numbers used in the ast::optoken enumeration
+ ID_OP_LOGICAL_OR = (ID_OP_OPERATOR | ID_OP_BINARY) + 12,
+ ID_OP_LOGICAL_AND = (ID_OP_OPERATOR | ID_OP_BINARY) + 13,
+ ID_OP_EQUAL = (ID_OP_OPERATOR | ID_OP_BINARY) + 17,
+ ID_OP_NOT_EQUAL = (ID_OP_OPERATOR | ID_OP_BINARY) + 18,
+ ID_OP_LESS = (ID_OP_OPERATOR | ID_OP_BINARY) + 19,
+ ID_OP_LESS_EQUAL = (ID_OP_OPERATOR | ID_OP_BINARY) + 20,
+ ID_OP_GREATER = (ID_OP_OPERATOR | ID_OP_BINARY) + 21,
+ ID_OP_GREATER_EQUAL = (ID_OP_OPERATOR | ID_OP_BINARY) + 22,
+ ID_OP_PLUS = (ID_OP_OPERATOR | ID_OP_UNARY | ID_OP_BINARY) + 25,
+ ID_OP_MINUS = (ID_OP_OPERATOR | ID_OP_UNARY | ID_OP_BINARY) + 26,
+ ID_OP_TIMES = (ID_OP_OPERATOR | ID_OP_BINARY) + 27,
+ ID_OP_DIVIDE = (ID_OP_OPERATOR | ID_OP_BINARY) + 28,
+ ID_OP_NOT = (ID_OP_OPERATOR | ID_OP_UNARY) + 35,
+
+ ID_IDENTIFIER = ID_OP_OPERATOR + 100,
+ ID_COMMENT,
+ ID_WHITESPACE,
+ ID_VOID_KWD,
+ ID_INT_KWD,
+ ID_IF_KWD,
+ ID_ELSE_KWD,
+ ID_WHILE_KWD,
+ ID_RETURN_KWD,
+ ID_UINT,
+ ID_BOOL
+ };
+}}
+
+#endif
+
+
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/vm.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/vm.cpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,160 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#include "config.hpp"
+#include "vm.hpp"
+
+#if defined(_MSC_VER)
+# pragma warning(disable: 4800) // forcing value to bool 'true' or 'false'
+ // (performance warning)
+#endif
+
+namespace client
+{
+ int vmachine::execute(
+ std::vector<int> const& code
+ , std::vector<int>::const_iterator pc
+ , std::vector<int>::iterator frame_ptr
+ )
+ {
+ std::vector<int>::iterator stack_ptr = frame_ptr;
+
+ while (true)
+ {
+ switch (*pc++)
+ {
+ case op_neg:
+ stack_ptr[-1] = -stack_ptr[-1];
+ break;
+
+ case op_not:
+ stack_ptr[-1] = !bool(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_eq:
+ --stack_ptr;
+ stack_ptr[-1] = bool(stack_ptr[-1] == stack_ptr[0]);
+ break;
+
+ case op_neq:
+ --stack_ptr;
+ stack_ptr[-1] = bool(stack_ptr[-1] != stack_ptr[0]);
+ break;
+
+ case op_lt:
+ --stack_ptr;
+ stack_ptr[-1] = bool(stack_ptr[-1] < stack_ptr[0]);
+ break;
+
+ case op_lte:
+ --stack_ptr;
+ stack_ptr[-1] = bool(stack_ptr[-1] <= stack_ptr[0]);
+ break;
+
+ case op_gt:
+ --stack_ptr;
+ stack_ptr[-1] = bool(stack_ptr[-1] > stack_ptr[0]);
+ break;
+
+ case op_gte:
+ --stack_ptr;
+ stack_ptr[-1] = bool(stack_ptr[-1] >= stack_ptr[0]);
+ break;
+
+ case op_and:
+ --stack_ptr;
+ stack_ptr[-1] = bool(stack_ptr[-1]) && bool(stack_ptr[0]);
+ break;
+
+ case op_or:
+ --stack_ptr;
+ stack_ptr[-1] = bool(stack_ptr[-1]) || bool(stack_ptr[0]);
+ break;
+
+ case op_load:
+ *stack_ptr++ = frame_ptr[*pc++];
+ break;
+
+ case op_store:
+ --stack_ptr;
+ frame_ptr[*pc++] = stack_ptr[0];
+ break;
+
+ case op_int:
+ *stack_ptr++ = *pc++;
+ break;
+
+ case op_true:
+ *stack_ptr++ = true;
+ break;
+
+ case op_false:
+ *stack_ptr++ = false;
+ break;
+
+ case op_jump:
+ pc += *pc;
+ break;
+
+ case op_jump_if:
+ if (!bool(stack_ptr[-1]))
+ pc += *pc;
+ else
+ ++pc;
+ --stack_ptr;
+ break;
+
+ case op_stk_adj:
+ stack_ptr += *pc++;
+ break;
+
+ case op_call:
+ {
+ int nargs = *pc++;
+ int jump = *pc++;
+
+ // a function call is a recursive call to execute
+ int r = execute(
+ code
+ , code.begin() + jump
+ , stack_ptr - nargs
+ );
+
+ // cleanup after return from function
+ stack_ptr[-nargs] = r; // get return value
+ stack_ptr -= (nargs - 1); // the stack will now contain
+ // the return value
+ }
+ break;
+
+ case op_return:
+ return stack_ptr[-1];
+ }
+ }
+ }
+}
+
+
Added: branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/vm.hpp
==============================================================================
--- (empty file)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/conjure2/vm.hpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,82 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_CONJURE_VM_HPP)
+#define BOOST_SPIRIT_CONJURE_VM_HPP
+
+#include <vector>
+
+namespace client
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // 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_not, // boolean negate the top stack entry
+ op_eq, // compare the top two stack entries for ==
+ op_neq, // compare the top two stack entries for !=
+ op_lt, // compare the top two stack entries for <
+ op_lte, // compare the top two stack entries for <=
+ op_gt, // compare the top two stack entries for >
+ op_gte, // compare the top two stack entries for >=
+
+ op_and, // logical and top two stack entries
+ op_or, // logical or top two stack entries
+
+ op_load, // load a variable
+ op_store, // store a variable
+
+ op_int, // push constant integer into the stack
+ op_true, // push constant 0 into the stack
+ op_false, // push constant 1 into the stack
+
+ op_jump_if, // jump to a relative position in the code if top stack
+ // evaluates to false
+ op_jump, // jump to a relative position in the code
+
+ op_stk_adj, // adjust the stack (for args and locals)
+ op_call, // function call
+ op_return // return from function
+ };
+
+ class vmachine
+ {
+ public:
+
+ vmachine(unsigned stackSize = 4096)
+ : stack(stackSize)
+ {
+ }
+
+ int execute(std::vector<int> const& code)
+ {
+ return execute(code, code.begin(), stack.begin());
+ }
+
+ std::vector<int> const& get_stack() const { return stack; };
+ std::vector<int>& get_stack() { return stack; };
+
+ private:
+
+ int execute(
+ std::vector<int> const& code // the program code
+ , std::vector<int>::const_iterator pc // program counter
+ , std::vector<int>::iterator frame_ptr // start of arguments and locals
+ );
+
+ std::vector<int> stack;
+ };
+}
+
+#endif
+
Modified: branches/release/libs/spirit/example/qi/compiler_tutorial/mini_c/compiler.cpp
==============================================================================
--- branches/release/libs/spirit/example/qi/compiler_tutorial/mini_c/compiler.cpp (original)
+++ branches/release/libs/spirit/example/qi/compiler_tutorial/mini_c/compiler.cpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -45,7 +45,8 @@
void function::add_var(std::string const& name)
{
- variables[name] = variables.size();
+ std::size_t n = variables.size();
+ variables[name] = n;
}
void function::link_to(std::string const& name, std::size_t address)
Modified: branches/release/libs/spirit/example/qi/parse_date.cpp
==============================================================================
--- branches/release/libs/spirit/example/qi/parse_date.cpp (original)
+++ branches/release/libs/spirit/example/qi/parse_date.cpp 2011-06-14 04:22:21 EDT (Tue, 14 Jun 2011)
@@ -120,7 +120,6 @@
std::cout << "Bye... :-) \n\n";
return 0;
- 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