1/*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3
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_CALC8_EXPRESSION_HPP)
8#define BOOST_SPIRIT_CALC8_EXPRESSION_HPP
9
10///////////////////////////////////////////////////////////////////////////////
11// Spirit v2.5 allows you to suppress automatic generation
12// of predefined terminals to speed up complation. With
13// BOOST_SPIRIT_NO_PREDEFINED_TERMINALS defined, you are
14// responsible in creating instances of the terminals that
15// you need (e.g. see qi::uint_type uint_ below).
16#define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
17///////////////////////////////////////////////////////////////////////////////
18
19///////////////////////////////////////////////////////////////////////////////
20// Uncomment this if you want to enable debugging
21// #define BOOST_SPIRIT_QI_DEBUG
22///////////////////////////////////////////////////////////////////////////////
23
24#include <boost/spirit/include/qi.hpp>
25#include "ast.hpp"
26#include "error_handler.hpp"
27#include <vector>
28
29namespace client { namespace parser
30{
31 namespace qi = boost::spirit::qi;
32 namespace ascii = boost::spirit::ascii;
33
34 ///////////////////////////////////////////////////////////////////////////////
35 // The expression grammar
36 ///////////////////////////////////////////////////////////////////////////////
37 template <typename Iterator>
38 struct expression : qi::grammar<Iterator, ast::expression(), ascii::space_type>
39 {
40 expression(error_handler<Iterator>& error_handler);
41
42 qi::rule<Iterator, ast::expression(), ascii::space_type>
43 expr, equality_expr, relational_expr,
44 logical_expr, additive_expr, multiplicative_expr
45 ;
46
47 qi::rule<Iterator, ast::operand(), ascii::space_type>
48 unary_expr, primary_expr
49 ;
50
51 qi::rule<Iterator, std::string(), ascii::space_type>
52 identifier
53 ;
54
55 qi::symbols<char, ast::optoken>
56 equality_op, relational_op, logical_op,
57 additive_op, multiplicative_op, unary_op
58 ;
59
60 qi::symbols<char>
61 keywords
62 ;
63 };
64}}
65
66#endif
67
68
69

source code of boost/libs/spirit/example/qi/compiler_tutorial/calc8/expression.hpp