forked from subailong/datalgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpr.h
56 lines (43 loc) · 1.24 KB
/
expr.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
48
49
50
51
52
53
54
55
56
//
// expr.h
// datalgo
//
// Created by Iyed Bennour on 19/11/14.
// Copyright (c) 2014 Iyed Bennour. All rights reserved.
//
#ifndef __datalgo__expr__
#define __datalgo__expr__
#include <stdio.h>
#include <assert.h>
#include <string>
#include <vector>
enum class Operation { ADD = 0, MINUS, MULT, DIV };
const Operation ops[] = {Operation::ADD, Operation::MINUS, Operation::MULT, Operation::DIV};
std::string opToString(Operation op);
class IExpr {
public:
virtual int eval() = 0;
static std::shared_ptr<IExpr> create(int value);
static std::shared_ptr<IExpr> create(std::shared_ptr<IExpr>& l, std::shared_ptr<IExpr>& r, Operation op);
virtual std::string toString() = 0;
};
class BinExpr : public IExpr{
public:
BinExpr(std::shared_ptr<IExpr>& _exprL, std::shared_ptr<IExpr>& _exprR, Operation _op);
virtual int eval();
std::string toString();
private:
Operation op;
std::shared_ptr<IExpr> exprL;
std::shared_ptr<IExpr> exprR;
};
class TerminalExpr : public IExpr {
public:
TerminalExpr(int val);
int eval();
std::string toString();
private:
int value;
};
std::vector<std::shared_ptr<IExpr>> find_solution(std::vector<std::shared_ptr<IExpr>>, std::shared_ptr<IExpr> sofar, int target);
#endif /* defined(__datalgo__expr__) */