-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsemantics.h
More file actions
69 lines (54 loc) · 1.55 KB
/
semantics.h
File metadata and controls
69 lines (54 loc) · 1.55 KB
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
58
59
60
61
62
63
64
65
66
67
#include "parsetree.h"
#include <map>
extern int yyparse(void);
extern ParseTree * top;
void openscope();
Symtab *closescope();
struct semantics {
// pure virtual function:
virtual string kind() = 0;
// at least one pure virtual function makes the class abstract
// (not instantiable.)
string ident;
};
struct S_class;
struct S_type : public semantics {
virtual string kind() { return "S_type"; }
string name; // usually a decaf symbol, but sometimes
int dimension;
// campbell's funky idea for types. FIXME.
// S_type's name can't be void.
};
struct S_primitive : public semantics {
virtual string kind() {return "S_primitive"; }
};
struct S_variable : public semantics {
S_type * type;
virtual string kind() { return "S_variable"; }
int sequenceNumber;
bool formal;
S_class * parentClass;
};
struct S_function : public semantics {
virtual string kind() { return "S_function"; }
vector<S_variable *> formals;
S_type * returnType; // NULL for a void function
bool ctor;
};
struct S_class : public semantics {
virtual string kind() { return "S_class"; }
S_class * parentClass; // extends
vector<semantics *> fields; // have to be S_function or S_variable
};
typedef map <string, semantics *> Dictionary;
struct Symtab {
// A class to represent symbol tables
// Chained togeher to represent nested scopes.
public:
Dictionary dict;
Symtab(Symtab *p);
semantics * lookup(string key);
semantics * local_lookup(string key);
void insert(string key, semantics * item);
Symtab * parent; // outer scope
};