forked from theDreamyFish/Compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpcat.hpp
More file actions
95 lines (81 loc) · 1.72 KB
/
pcat.hpp
File metadata and controls
95 lines (81 loc) · 1.72 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#define TABLESIZE 1000
#define STACKDEPTH 100
#define MAXFUCTIONSTACK 100
typedef enum {typeTerminal, typeNonterminal } nodeEnum;
typedef enum {nullv, intv, realv, boolv, stringv, returnFlag, exitFlag} varEnum;
typedef enum {varv, typev, arrayv } varElementEnum;
/* Terminal */
typedef struct {
char *label;
union {
int v_int;
float v_real;
char *v_string;
char *v_id; // this may be changed to integer value; (after constructing an id table)
int v_null;
};
} terminalNodeType;
/* Nontermilan */
typedef struct {
char *label;
int nops;
struct nodeTypeTag *op[1];
} nonterminalNodeType;
typedef struct nodeTypeTag {
nodeEnum type;
union {
terminalNodeType t;
nonterminalNodeType nt;
};
} nodeType;
typedef struct variable{
varEnum type;
union{
int nullv;
int intv;
double realv;
int boolv;
char *stringv;
int returnFlag;
int exitFlag;
};
} var;
typedef struct varElementStruct{
char *label;
varElementEnum type;
union {
var t;
struct arrayVar {
//char *label; // type of array, may need
int nops;
struct varElementStruct *op[1];
} arrayv;
struct typeVar {
int nops;
char *label[1]; //may have bugs need to be checked
struct varElementStruct *op[1];
} typev;
};
} varElement;
typedef struct {
char *label;
nodeType *address;
} nameElement;
typedef struct contextStruct{
struct contextStruct *callFrom;//for main(), callFrom = NULL
nameElement typeTable[TABLESIZE];
nameElement procedureTable[TABLESIZE];
varElement varTable[TABLESIZE];
int typeTableSize;
int procedureTableSize;
int varTableSize;
int depth;
var returnValue;
} context;
int line_num;
int col_num;
char line_buffer[3000];