OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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#include "expression.hpp"
8#include "error_handler.hpp"
9#include "annotation.hpp"
10#include <boost/spirit/include/phoenix_function.hpp>
11#include <boost/spirit/include/phoenix.hpp>
12#include <boost/fusion/adapted.hpp>
13//#include <boost/spirit/include/qi_lit.hpp>
14
15namespace client { namespace parser
16{
17 template <typename Iterator>
19 : expression::base_type(expr)
20 {
21 qi::_1_type _1;
22 // qi::_2_type _2;
23 qi::_3_type _3;
24 qi::_4_type _4;
25 qi::_a_type _a;
26
27 qi::char_type char_;
28 qi::uint_type uint_;
29 qi::double_type double_;
30 qi::_val_type _val;
31 qi::raw_type raw;
32 qi::lexeme_type lexeme;
33 qi::lit_type lit;
34 qi::no_skip_type no_skip;
35 qi::omit_type omit;
36 qi::alpha_type alpha;
37 qi::alnum_type alnum;
38 qi::bool_type bool_;
39
40 using qi::on_error;
41 using qi::on_success;
42 using qi::fail;
44
45 typedef function<client::error_handler<Iterator> > error_handler_function;
46 typedef function<client::annotation<Iterator> > annotation_function;
47
49 // Tokens
51 ("||", ast::op_or)
52 ;
53
55 ("&&", ast::op_and)
56 ;
57
58 equality_op.add
59 ("==", ast::op_equal)
60 ("!=", ast::op_not_equal)
61 ;
62
64 ("<", ast::op_less)
65 ("<=", ast::op_less_equal)
66 (">", ast::op_greater)
68 ;
69
70 additive_op.add
71 ("+", ast::op_plus)
72 ("-", ast::op_minus)
73 ;
74
76 ("*", ast::op_times)
77 ("/", ast::op_divide)
78 ;
79
80 unary_op.add
81 ("+", ast::op_positive)
82 ("-", ast::op_negative)
83 ("!", ast::op_not)
84 ;
85
86 keywords.add
87 ("true")
88 ("false")
89 ;
90
92 // Main expression grammar
93 expr =
94 logical_or_expr.alias()
95 ;
96
100 ;
101
105 ;
106
110 ;
111
115 ;
116
120 ;
121
125 ;
126
127 unary_expr =
129 | (unary_op > unary_expr)
130 ;
131
135 | identifier
136 | bool_
137 | ('(' > expr > ')')
138 ;
139
141 double_
142 | uint_
143 ;
144
146 (identifier >> '(')
148 > ')'
149 ;
150
152 omit [ char_("'\"") [_a = _1] ]
153 >> no_skip [ *(char_ - char_(_a)) ]
154 >> lit(_a)
155 ;
156
157 argument_list = -((expr | quoted_string) % ',');
158
159 identifier =
160 !lexeme[keywords >> !(alnum | '_')]
161 >> raw[lexeme[(alpha | '_') >> *(alnum | '_')]]
162 ;
163
165 // Debugging and error handling and reporting support.
166 BOOST_SPIRIT_DEBUG_NODES(
167 (expr)
174 (unary_expr)
178 (identifier)
180 );
181
183 // Error handling: on error in expr, call error_handler.
184 on_error<fail>(expr,
185 error_handler_function(error_handler)(
186 std::string("Error! Expecting "), _4, _3));
187
189 // Annotation: on success in primary_expr, call annotation.
190 on_success(primary_expr,
191 annotation_function(error_handler.iters)(_val, _1));
192 }
193}}
py::list function(PolynomialPatch *patch, py::list point)
constexpr double alpha
The fine structure constant, no dimension.
Definition: Physics.h:72
@ op_plus
Definition: ast.hpp:63
@ op_not
Definition: ast.hpp:69
@ op_not_equal
Definition: ast.hpp:71
@ op_or
Definition: ast.hpp:77
@ op_less
Definition: ast.hpp:72
@ op_equal
Definition: ast.hpp:70
@ op_times
Definition: ast.hpp:65
@ op_and
Definition: ast.hpp:76
@ op_minus
Definition: ast.hpp:64
@ op_less_equal
Definition: ast.hpp:73
@ op_greater
Definition: ast.hpp:74
@ op_greater_equal
Definition: ast.hpp:75
@ op_positive
Definition: ast.hpp:67
@ op_negative
Definition: ast.hpp:68
@ op_divide
Definition: ast.hpp:66
std::vector< Iterator > iters
qi::symbols< char > keywords
Definition: expression.hpp:77
qi::symbols< char, ast::optoken > unary_op
Definition: expression.hpp:73
qi::symbols< char, ast::optoken > multiplicative_op
Definition: expression.hpp:72
qi::rule< Iterator, ast::expression(), qi::locals< char >, skipper< Iterator > > additive_expr
Definition: expression.hpp:46
qi::symbols< char, ast::optoken > logical_and_op
Definition: expression.hpp:70
qi::rule< Iterator, ast::expression(), qi::locals< char >, skipper< Iterator > > relational_expr
Definition: expression.hpp:44
qi::rule< Iterator, std::string(), qi::locals< char >, skipper< Iterator > > quoted_string
Definition: expression.hpp:67
qi::symbols< char, ast::optoken > relational_op
Definition: expression.hpp:71
qi::symbols< char, ast::optoken > additive_op
Definition: expression.hpp:72
qi::symbols< char, ast::optoken > logical_or_op
Definition: expression.hpp:70
qi::rule< Iterator, ast::expression(), qi::locals< char >, skipper< Iterator > > logical_and_expr
Definition: expression.hpp:45
expression(error_handler< Iterator > &error_handler)
qi::rule< Iterator, ast::operand(), qi::locals< char >, skipper< Iterator > > unary_expr
Definition: expression.hpp:50
qi::rule< Iterator, ast::expression(), qi::locals< char >, skipper< Iterator > > equality_expr
Definition: expression.hpp:44
qi::rule< Iterator, ast::function_call(), qi::locals< char >, skipper< Iterator > > function_call
Definition: expression.hpp:55
qi::rule< Iterator, ast::expression(), qi::locals< char >, skipper< Iterator > > expr
Definition: expression.hpp:44
qi::rule< Iterator, ast::operand(), qi::locals< char >, skipper< Iterator > > constant_expr
Definition: expression.hpp:51
qi::rule< Iterator, ast::expression(), qi::locals< char >, skipper< Iterator > > multiplicative_expr
Definition: expression.hpp:47
qi::symbols< char, ast::optoken > equality_op
Definition: expression.hpp:71
qi::rule< Iterator, ast::operand(), qi::locals< char >, skipper< Iterator > > primary_expr
Definition: expression.hpp:50
qi::rule< Iterator, ast::expression(), qi::locals< char >, skipper< Iterator > > logical_or_expr
Definition: expression.hpp:45
qi::rule< Iterator, std::list< ast::function_call_argument >(), qi::locals< char >, skipper< Iterator > > argument_list
Definition: expression.hpp:59
qi::rule< Iterator, std::string(), qi::locals< char >, skipper< Iterator > > identifier
Definition: expression.hpp:63