Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
grammar.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file ored/scripting/grammar.hpp
20 \brief payoff script grammar
21 \ingroup utilities
22*/
23
24#pragma once
25
27
28#include <boost/phoenix.hpp>
29#include <boost/spirit/include/qi.hpp>
30#include <boost/spirit/include/support_line_pos_iterator.hpp>
31
32#include <ql/types.hpp>
33
34#include <stack>
35#include <string>
36#include <vector>
37
38namespace ore {
39namespace data {
40
41using namespace QuantLib;
42
43namespace qi = boost::spirit::qi;
44namespace phoenix = boost::phoenix;
45
46using ScriptGrammarIterator = boost::spirit::line_pos_iterator<std::string::const_iterator>;
47
48// ast node annotator
49
51 ASTNodeAnnotation(std::stack<ASTNodePtr>& evalStack, const ScriptGrammarIterator first)
52 : evalStack_(evalStack), first_(first) {}
53 void operator()(const ScriptGrammarIterator f, const ScriptGrammarIterator l) const;
54 std::stack<ASTNodePtr>& evalStack_;
56};
57
58// grammar
59
60struct ScriptGrammar : public qi::grammar<ScriptGrammarIterator, qi::space_type> {
64 boost::spirit::info errorWhat;
65 std::stack<ASTNodePtr> evalStack;
66
67private:
68 qi::rule<ScriptGrammarIterator, std::string(), qi::space_type> keyword, varname;
69 qi::rule<ScriptGrammarIterator, qi::space_type> varexpr, instructionseq, instruction, declaration, ifthenelse, loop,
72};
73
74} // namespace data
75} // namespace ore
abstract syntax tree for payoff scripting
@ data
Definition: log.hpp:77
boost::spirit::line_pos_iterator< std::string::const_iterator > ScriptGrammarIterator
Definition: grammar.hpp:46
Serializable Credit Default Swap.
Definition: namespaces.docs:23
ASTNodeAnnotation(std::stack< ASTNodePtr > &evalStack, const ScriptGrammarIterator first)
Definition: grammar.hpp:51
const ScriptGrammarIterator first_
Definition: grammar.hpp:55
void operator()(const ScriptGrammarIterator f, const ScriptGrammarIterator l) const
Definition: grammar.cpp:256
std::stack< ASTNodePtr > & evalStack_
Definition: grammar.hpp:54
qi::rule< ScriptGrammarIterator, qi::space_type > loop
Definition: grammar.hpp:69
qi::rule< ScriptGrammarIterator, qi::space_type > condition2
Definition: grammar.hpp:70
ScriptGrammarIterator errorBegin
Definition: grammar.hpp:63
qi::rule< ScriptGrammarIterator, qi::space_type > instructionseq
Definition: grammar.hpp:69
qi::rule< ScriptGrammarIterator, qi::space_type > require
Definition: grammar.hpp:70
std::stack< ASTNodePtr > evalStack
Definition: grammar.hpp:65
qi::rule< ScriptGrammarIterator, qi::space_type > ifthenelse
Definition: grammar.hpp:69
ASTNodeAnnotation annotate
Definition: grammar.hpp:71
qi::rule< ScriptGrammarIterator, qi::space_type > instruction
Definition: grammar.hpp:69
ScriptGrammarIterator errorEnd
Definition: grammar.hpp:63
qi::rule< ScriptGrammarIterator, qi::space_type > permute
Definition: grammar.hpp:70
qi::rule< ScriptGrammarIterator, qi::space_type > declaration
Definition: grammar.hpp:69
qi::rule< ScriptGrammarIterator, qi::space_type > assignment
Definition: grammar.hpp:70
qi::rule< ScriptGrammarIterator, std::string(), qi::space_type > keyword
Definition: grammar.hpp:68
qi::rule< ScriptGrammarIterator, qi::space_type > varexpr
Definition: grammar.hpp:69
qi::rule< ScriptGrammarIterator, qi::space_type > factor
Definition: grammar.hpp:70
qi::rule< ScriptGrammarIterator, qi::space_type > sort
Definition: grammar.hpp:70
qi::rule< ScriptGrammarIterator, qi::space_type > product
Definition: grammar.hpp:70
qi::rule< ScriptGrammarIterator, qi::space_type > term
Definition: grammar.hpp:70
qi::rule< ScriptGrammarIterator, qi::space_type > condition
Definition: grammar.hpp:70
qi::rule< ScriptGrammarIterator, qi::space_type > condition3
Definition: grammar.hpp:70
ScriptGrammarIterator errorPos
Definition: grammar.hpp:63
boost::spirit::info errorWhat
Definition: grammar.hpp:64
qi::rule< ScriptGrammarIterator, std::string(), qi::space_type > varname
Definition: grammar.hpp:68