The Sparta Modeling Framework
Loading...
Searching...
No Matches
ExpressionParser.hpp
1// <ExpressionParser> -*- C++ -*-
2
3#pragma once
4
5#include <iostream>
6#include <sstream>
7
12
13#include "sparta/statistics/Expression.hpp"
15#include "sparta/statistics/ExpressionGrammar.hpp"
16
17#include <memory>
18#include <stack>
19
20namespace sparta {
21 namespace statistics {
22 namespace expression {
23
29{
35 Expression parse_temp_;
36
37 const grammar::ExpressionGrammar grammar_;
38
39public:
40
52 std::vector<const TreeNode*>& already_used,
53 const StatisticPairs &report_si) :
54 grammar_(n, already_used, report_si)
55 { }
56
57 Expression&& parse(const std::string& input) {
58 using boost::spirit::ascii::space;
59
60 std::string::const_iterator iter = input.begin();
61 std::string::const_iterator end = input.end();
62 bool r = qi::phrase_parse(iter, end, grammar_, space, parse_temp_);
63
64 if (!r || iter != end){
65 throw SpartaException("Parsing expression \"") << input << "\" failed to parse remainder"
66 << " \"" << std::string(iter, end) << "\". Note that this does not indicate which "
67 "part of the expression was wrong, but how much the recursive parser could "
68 "properly interpret";
69 }
70
71 return std::move(parse_temp_);
72 }
73};
74
75 } // namespace expression
76 } // namespace statistics
77} // namespace sparta
This exists mainly to remove circular dependencies on StatVariable and SimVariable: Expression -> Sta...
Set of macros for Sparta assertions. Caught by the framework.
Exception class for all of Sparta.
Contains a StatisticInstance which refers to a StatisticDef or Counter and some local state to comput...
Basic Node framework in sparta device tree composite pattern.
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
Class for parsing statistical expressions based on a specific TreeNode context.
ExpressionParser(TreeNode *n, std::vector< const TreeNode * > &already_used, const StatisticPairs &report_si)
Construct a parser in the context of a specific TreeNode.
Expression container/builder. Contains a single ExpressionNode representing the root of an expression...
void end()
Notify every item in this expression to end the current computation window.
std::vector< stat_pair_t > StatisticPairs
Type for storing a list of stat_pair_t.
Macros for handling exponential backoff.