33#ifndef _PFUNCTIONGRAMMAR_H_
34#define _PFUNCTIONGRAMMAR_H_
37#include <boost/version.hpp>
38#if BOOST_VERSION < 106100
39# error "Boost version 1.61.0 or higher is required for Spirit X3. Please upgrade Boost."
42#include "PFunctionAst.h"
43#include <boost/spirit/home/x3.hpp>
45namespace x3 = boost::spirit::x3;
80 add(
"+", ast::op_plus)(
"-", ast::op_minus);
96 add(
"*", ast::op_times)(
"/", ast::op_divide);
114 (
"COS", ast::fun_cos)
115 (
"SIN", ast::fun_sin)
116 (
"TAN", ast::fun_tan)
117 (
"COSH", ast::fun_cosh)
118 (
"SINH", ast::fun_sinh)
119 (
"TANH", ast::fun_tanh)
120 (
"ACOS", ast::fun_acos)
121 (
"ASIN", ast::fun_asin)
122 (
"ATAN", ast::fun_atan)
123 (
"ACOSH", ast::fun_acosh)
124 (
"ASINH", ast::fun_asinh)
125 (
"ATANH", ast::fun_atanh)
126 (
"LOG", ast::fun_log)
128 (
"EXP", ast::fun_exp)
129 (
"SQRT", ast::fun_sqrt);
145 add(
"PI", ast::constant::pi)(
"GAMMA_MU", ast::constant::gamma_mu);
156 x3::rule<class assignment, ast::assignment>
const assignment =
"assignment";
159 x3::rule<class expression, ast::expression>
const expression =
"expression";
162 x3::rule<class term, ast::expression>
const term =
"term";
165 x3::rule<class factor, ast::operand>
const factor =
"factor";
168 x3::rule<class constant, ast::constant>
const constant =
"constant";
171 x3::rule<class parameter, ast::parameter>
const parameter =
"parameter";
174 x3::rule<class map_ref, ast::map_ref>
const map =
"map";
177 x3::rule<class function_call, ast::function_call>
const function =
"function";
180 x3::rule<class power_call, ast::power_call>
const power =
"power";
237 | (lit(
"B") >> attr(ast::constant::field) >> attr(
false) >> attr(0))
238 | (lit(
"-B") >> attr(ast::constant::field) >> attr(
true) >> attr(0))
239 | (lit(
"EN") >> attr(ast::constant::energy) >> attr(
false) >> attr(0))
240 | (lit(
"-EN") >> attr(ast::constant::energy) >> attr(
true) >> attr(0))
241 | (lit(
'T') >> attr(ast::constant::temp) >> attr(
false) >> int_)
242 | (lit(
"-T") >> attr(ast::constant::temp) >> attr(
true) >> int_);
252 (lexeme[lit(
"-PAR") >> int_] >> attr(
true))
253 | (lit(
"PAR") >> int_ >> attr(
false));
262 (lexeme[lit(
"-MAP") >> int_] >> attr(
true))
263 | (lit(
"MAP") >> int_ >> attr(
false));
Boost.Spirit X3 grammar definitions for parsing function expressions.
auto const assignment_def
Assignment rule: FUN# = expression.
fun_tok_ fun_tok
Global instance of function name symbol table.
multiplicative_op_ multiplicative_op
Global instance of multiplicative operator symbol table.
auto const expression_def
Expression rule: term ((+|-) term)*.
x3::rule< class parameter, ast::parameter > const parameter
Parameter reference: PAR# or -PAR#.
x3::rule< class term, ast::expression > const term
Term with multiplication/division (higher precedence)
x3::rule< class function_call, ast::function_call > const function
Function call: FUNC(expression)
auto const function_def
Function rule: FUNC(expression)
auto const factor_def
Factor rule: the atomic elements of expressions.
auto const constant_def
Constant rule: PI | GAMMA_MU | B | -B | EN | -EN | T# | -T#.
additive_op_ additive_op
Global instance of additive operator symbol table.
x3::rule< class map_ref, ast::map_ref > const map
Map reference: MAP# or -MAP#.
x3::rule< class assignment, ast::assignment > const assignment
Top-level rule: FUN# = expression.
auto const term_def
Term rule: factor ((*|/) factor)*.
auto const parameter_def
Parameter rule: PAR# | -PAR#.
auto const map_def
Map rule: MAP# | -MAP#.
x3::rule< class factor, ast::operand > const factor
Factor: literal, constant, parameter, function, or parenthesized expression (highest precedence)
x3::rule< class constant, ast::constant > const constant
Constant: PI, GAMMA_MU, B, EN, or T#.
auto const power_def
Power rule: POW(base, exponent)
x3::rule< class expression, ast::expression > const expression
Expression with addition/subtraction (lowest precedence)
const_tok_ const_tok
Global instance of constant name symbol table.
x3::rule< class power_call, ast::power_call > const power
Power operation: POW(base, exponent)
Top-level namespace for musrfit components.
auto const & function_grammar()
Provides access to the top-level grammar rule.
Symbol table for additive operators (+ and -).
Symbol table for named constants.
Symbol table for mathematical function names.
Symbol table for multiplicative operators (* and /).