1 /*============================================================================= 2 Copyright (c) 2001-2011 Joel de Guzman 3 Copyright (c) 2001-2011 Hartmut Kaiser 4 5 Distributed under the Boost Software License, Version 1.0. (See accompanying 6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 =============================================================================*/ 8 #if !defined(BOOST_SPIRIT_CONJURE_EXPRESSION_HPP) 9 #define BOOST_SPIRIT_CONJURE_EXPRESSION_HPP 10 11 /////////////////////////////////////////////////////////////////////////////// 12 // Spirit v2.5 allows you to suppress automatic generation 13 // of predefined terminals to speed up complation. With 14 // BOOST_SPIRIT_NO_PREDEFINED_TERMINALS defined, you are 15 // responsible in creating instances of the terminals that 16 // you need (e.g. see qi::uint_type uint_ below). 17 #define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS 18 /////////////////////////////////////////////////////////////////////////////// 19 20 /////////////////////////////////////////////////////////////////////////////// 21 // Uncomment this if you want to enable debugging 22 // #define BOOST_SPIRIT_QI_DEBUG 23 /////////////////////////////////////////////////////////////////////////////// 24 25 #include <boost/spirit/include/qi.hpp> 26 #include "ast.hpp" 27 #include "error_handler.hpp" 28 #include <vector> 29 30 namespace client { namespace parser 31 { 32 namespace qi = boost::spirit::qi; 33 namespace ascii = boost::spirit::ascii; 34 35 /////////////////////////////////////////////////////////////////////////////// 36 // The expression grammar 37 /////////////////////////////////////////////////////////////////////////////// 38 template <typename Iterator, typename Lexer> 39 struct expression : qi::grammar<Iterator, ast::expression()> 40 { 41 typedef error_handler<typename Lexer::base_iterator_type, Iterator> 42 error_handler_type; 43 44 expression(error_handler_type& error_handler, Lexer const& l); 45 46 Lexer const& lexer; 47 48 qi::rule<Iterator, ast::expression()> expr; 49 qi::rule<Iterator, ast::operand()> unary_expr, postfix_expr; 50 qi::rule<Iterator, ast::function_call()> function_call; 51 qi::rule<Iterator, std::list<ast::expression>()> argument_list; 52 qi::rule<Iterator, std::string()> identifier; 53 qi::rule<Iterator, ast::primary_expr()> primary_expr; 54 }; 55 }} 56 57 #endif 58 59 60