OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
expression_def.hpp
Go to the documentation of this file.
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
8/*
9 with boost 1.81 and newer we get multiple definition of
10 `boost::phoenix::placeholders::uargX` errors. A solution
11 suggested in https://github.com/boostorg/phoenix/issues/111
12 is to define BOOST_PHOENIX_STL_TUPLE_H_ so that
13 boost/stl/tuple.h is not included in boost/phoenix.hpp
14*/
15#define BOOST_PHOENIX_STL_TUPLE_H_
16
17#include "expression.hpp"
18#include "error_handler.hpp"
19#include "annotation.hpp"
20#include <boost/phoenix/function.hpp>
21#include <boost/phoenix.hpp>
22#include <boost/fusion/adapted.hpp>
23//#include <boost/spirit/include/qi_lit.hpp>
24
25namespace client { namespace parser
26{
27 template <typename Iterator>
29 : expression::base_type(expr)
30 {
31 qi::_1_type _1;
32 // qi::_2_type _2;
33 qi::_3_type _3;
34 qi::_4_type _4;
35 qi::_a_type _a;
36
37 qi::char_type char_;
38 qi::uint_type uint_;
39 qi::double_type double_;
40 qi::_val_type _val;
41 qi::raw_type raw;
42 qi::lexeme_type lexeme;
43 qi::lit_type lit;
44 qi::no_skip_type no_skip;
45 qi::omit_type omit;
46 qi::alpha_type alpha;
47 qi::alnum_type alnum;
48 qi::bool_type bool_;
49
50 using qi::on_error;
51 using qi::on_success;
52 using qi::fail;
53 using boost::phoenix::function;
54
55 typedef function<client::error_handler<Iterator> > error_handler_function;
56 typedef function<client::annotation<Iterator> > annotation_function;
57
59 // Tokens
61 ("||", ast::op_or)
62 ;
63
65 ("&&", ast::op_and)
66 ;
67
68 equality_op.add
69 ("==", ast::op_equal)
70 ("!=", ast::op_not_equal)
71 ;
72
74 ("<", ast::op_less)
75 ("<=", ast::op_less_equal)
76 (">", ast::op_greater)
78 ;
79
80 additive_op.add
81 ("+", ast::op_plus)
82 ("-", ast::op_minus)
83 ;
84
86 ("*", ast::op_times)
87 ("/", ast::op_divide)
88 ;
89
90 unary_op.add
91 ("+", ast::op_positive)
92 ("-", ast::op_negative)
93 ("!", ast::op_not)
94 ;
95
96 keywords.add
97 ("true")
98 ("false")
99 ;
100
102 // Main expression grammar
103 expr =
104 logical_or_expr.alias()
105 ;
106
110 ;
111
115 ;
116
120 ;
121
125 ;
126
130 ;
131
135 ;
136
137 unary_expr =
139 | (unary_op > unary_expr)
140 ;
141
145 | identifier
146 | bool_
147 | ('(' > expr > ')')
148 ;
149
151 double_
152 | uint_
153 ;
154
156 (identifier >> '(')
158 > ')'
159 ;
160
162 omit [ char_("'\"") [_a = _1] ]
163 >> no_skip [ *(char_ - char_(_a)) ]
164 >> lit(_a)
165 ;
166
167 argument_list = -((expr | quoted_string) % ',');
168
169 identifier =
170 !lexeme[keywords >> !(alnum | '_')]
171 >> raw[lexeme[(alpha | '_') >> *(alnum | '_')]]
172 ;
173
175 // Debugging and error handling and reporting support.
176 BOOST_SPIRIT_DEBUG_NODES(
177 (expr)
184 (unary_expr)
188 (identifier)
190 );
191
193 // Error handling: on error in expr, call error_handler.
194 on_error<fail>(expr,
195 error_handler_function(error_handler)(
196 std::string("Error! Expecting "), _4, _3));
197
199 // Annotation: on success in primary_expr, call annotation.
200 on_success(primary_expr,
201 annotation_function(error_handler.iters)(_val, _1));
202 }
203}}
qi::symbols< char > keywords
qi::symbols< char, ast::optoken > unary_op
qi::symbols< char, ast::optoken > multiplicative_op
qi::rule< Iterator, ast::expression(), qi::locals< char >, skipper< Iterator > > additive_expr
qi::symbols< char, ast::optoken > logical_and_op
qi::rule< Iterator, ast::expression(), qi::locals< char >, skipper< Iterator > > relational_expr
qi::rule< Iterator, std::string(), qi::locals< char >, skipper< Iterator > > quoted_string
qi::symbols< char, ast::optoken > relational_op
qi::symbols< char, ast::optoken > additive_op
qi::symbols< char, ast::optoken > logical_or_op
qi::rule< Iterator, ast::expression(), qi::locals< char >, skipper< Iterator > > logical_and_expr
expression(error_handler< Iterator > &error_handler)
qi::rule< Iterator, ast::operand(), qi::locals< char >, skipper< Iterator > > unary_expr
qi::rule< Iterator, ast::expression(), qi::locals< char >, skipper< Iterator > > equality_expr
qi::rule< Iterator, ast::function_call(), qi::locals< char >, skipper< Iterator > > function_call
qi::rule< Iterator, ast::expression(), qi::locals< char >, skipper< Iterator > > expr
qi::rule< Iterator, ast::operand(), qi::locals< char >, skipper< Iterator > > constant_expr
qi::rule< Iterator, ast::expression(), qi::locals< char >, skipper< Iterator > > multiplicative_expr
qi::symbols< char, ast::optoken > equality_op
qi::rule< Iterator, ast::operand(), qi::locals< char >, skipper< Iterator > > primary_expr
qi::rule< Iterator, ast::expression(), qi::locals< char >, skipper< Iterator > > logical_or_expr
qi::rule< Iterator, std::list< ast::function_call_argument >(), qi::locals< char >, skipper< Iterator > > argument_list
qi::rule< Iterator, std::string(), qi::locals< char >, skipper< Iterator > > identifier