-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathast.cpp
More file actions
41 lines (34 loc) · 867 Bytes
/
ast.cpp
File metadata and controls
41 lines (34 loc) · 867 Bytes
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
#include "symtab.h"
#include "ast.h"
IdNode::IdNode (char *name, int line)
{
myType t = getSymbol (name);
if (t == UNKNOWN) {
errorMsg ("line %d: variable %s is undefined\n", line, name);
t = _INT;
}
_type = t;
strcpy (this->_name, name);
_line = line;
}
BinaryOp::BinaryOp (enum op op, Exp *left, Exp *right, int line)
{
this->_op = op;
this->_left = left;
this->_right = right;
_line = line;
if (left->_type != right->_type)
_type = _FLOAT;
else
_type = left->_type;
}
AssignStmt::AssignStmt (IdNode *lhs, Exp *rhs, int line)
: Stmt () // call base class (super class) constructor
{
_lhs = lhs;
_rhs = rhs;
_line = line;
}
SwitchStmt::SwitchStmt (Exp *exp, Case *caselist, Stmt *default_stmt, int line) {
_exp = exp; _caselist = caselist; _default_stmt = default_stmt; _line = line;
}