-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormulaAST.h
47 lines (36 loc) · 1.16 KB
/
FormulaAST.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include "FormulaLexer.h"
#include "common.h"
#include <forward_list>
#include <functional>
#include <stdexcept>
namespace ASTImpl {
class Expr;
}
class ParsingError : public std::runtime_error {
using std::runtime_error::runtime_error;
};
using SheetArgs = std::function<double(Position)>;
class FormulaAST {
public:
explicit FormulaAST(std::unique_ptr<ASTImpl::Expr> root_expr,
std::forward_list<Position> cells);
FormulaAST(FormulaAST&&) = default;
FormulaAST& operator=(FormulaAST&&) = default;
~FormulaAST();
double Execute(const SheetArgs&) const;
void PrintCells(std::ostream& out) const;
void Print(std::ostream& out) const;
void PrintFormula(std::ostream& out) const;
std::forward_list<Position>& GetCells() {
return cells_;
}
const std::forward_list<Position>& GetCells() const {
return cells_;
}
private:
std::unique_ptr<ASTImpl::Expr> root_expr_;
std::forward_list<Position> cells_;
};
FormulaAST ParseFormulaAST(std::istream& in);
FormulaAST ParseFormulaAST(const std::string& in_str);