1 /*=============================================================================
2 Copyright (c) 2001-2014 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #if !defined(BOOST_SPIRIT_X3_CALC9_AST_HPP)
8 #define BOOST_SPIRIT_X3_CALC9_AST_HPP
10 #include <boost/spirit/home/x3/support/ast/variant.hpp>
11 #include <boost/spirit/home/x3/support/ast/position_tagged.hpp>
12 #include <boost/fusion/include/io.hpp>
13 #include <boost/optional.hpp>
16 namespace client { namespace ast
18 ///////////////////////////////////////////////////////////////////////////
20 ///////////////////////////////////////////////////////////////////////////
21 namespace x3 = boost::spirit::x3;
27 struct variable : x3::position_tagged
29 variable(std::string const& name = "") : name(name) {}
38 , x3::forward_ast<unary>
39 , x3::forward_ast<expression>
42 using base_type::base_type;
43 using base_type::operator=;
71 struct operation : x3::position_tagged
77 struct expression : x3::position_tagged
80 std::list<operation> rest;
83 struct assignment : x3::position_tagged
89 struct variable_declaration
95 struct while_statement;
96 struct statement_list;
102 , boost::recursive_wrapper<if_statement>
103 , boost::recursive_wrapper<while_statement>
104 , boost::recursive_wrapper<statement_list>
107 using base_type::base_type;
108 using base_type::operator=;
111 struct statement_list : std::list<statement> {};
115 expression condition;
117 boost::optional<statement> else_;
120 struct while_statement
122 expression condition;
126 // print functions for debugging
127 inline std::ostream& operator<<(std::ostream& out, nil)
133 inline std::ostream& operator<<(std::ostream& out, variable const& var)
135 out << var.name; return out;