-
Notifications
You must be signed in to change notification settings - Fork 2
/
ast.cc
57 lines (44 loc) · 1.01 KB
/
ast.cc
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
57
#include "ast.h"
#include <string.h>
#include <algorithm>
#include <cassert>
#include <iostream>
#include <sstream>
#include "log.h"
using std::string;
Binary::operator std::string() {
return "(" + string(*left) + op.lexeme + string(*right) + ")";
}
Unary::operator std::string() { return op.lexeme + string(*child); }
Integer::operator std::string() {
std::stringstream ss;
ss << value;
return ss.str();
}
Double::operator std::string() {
std::stringstream ss;
ss << value;
return ss.str();
}
String::operator std::string() { return value; }
Char::operator std::string() {
string s;
s.push_back(value);
return s;
}
Integer::Integer(Token token) {
std::stringstream ss(token.lexeme);
ss >> value;
}
Double::Double(Token token) {
std::stringstream ss(token.lexeme);
ss >> value;
}
Boolean::operator std::string() { return value ? "true" : "false"; }
Char::Char(Token token) {
std::string s = token.lexeme;
if (s.size() == 1)
value = s[0];
else
abortMsg("bad char literal");
}