-
Notifications
You must be signed in to change notification settings - Fork 0
/
name.h
49 lines (34 loc) · 1.11 KB
/
name.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
#pragma once
#ifndef NAME_H_
#define NAME_H_
#include "parser.h"
#include "expression.h"
#include <string>
#include <stdexcept>
#include <exception>
namespace compiler {
class Name : public Expression {
typedef std::string name_str_t;
typedef Parser::TokenType token_t;
public:
name_str_t name;
token_t token;
Name(name_str_t namestr, token_t tk, const expression_ptr_t r = nullptr)
: Expression(nullptr, r), name(namestr), token(tk) {
}
virtual double exec() const override {
throw std::runtime_error("this function should not be called.");
}
};
class Assign : public Name {
typedef std::string name_str_t;
typedef Parser::TokenType token_t;
public:
Assign(name_str_t namestr, token_t tk, const expression_ptr_t r)
:Name(namestr, tk, r) {
}
virtual double exec() const override { return this->right_->exec(); }
virtual std::string op() { return "="; }
};
}
#endif // !NAME_H_