-
Notifications
You must be signed in to change notification settings - Fork 9
/
interpreterClass.c
148 lines (111 loc) · 3.77 KB
/
interpreterClass.c
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include <sys/stat.h>
#include "baik_word.h"
#include "baik_struct.h"
#include "val_label.h"
#include "baik_lexer.h"
#ifdef WINDOWS
#pragma warning(disable:4996)
#pragma warning(disable:4244)
#endif
extern BAIK_LEX lex;
extern BAIK_ADDR pg;
#define MAX_CLASS_SUB_DEPTH 64
extern class_sub_deep;
extern char currentClass[MAX_STRING_LEN];
extern void varstack_printData(void);
extern void Interpreter( void );
void InterpreterClassSub( int endSub, char className[MAX_STRING_LEN] )
{
/* Set Current Class Name Running */
memset(¤tClass, '\0', sizeof(currentClass));
strcpy(currentClass, className);
//class_sub_deep++;
//if(class_sub_deep > MAX_CLASS_SUB_DEPTH )
// Error("Melebihi kapasitas rekursif");
// printf("=== start interpreterClass ...\n");
do{
Interpreter();
}while( pg.pt <= endSub && strncmp(lex.detail.string , "}", 1) != 0
&& lex.type != _EOF );
//}while( pg.pt <= endSub && lex.type != _EOF );
// class_sub_deep--;
// printf("interpretClassSub finish , back to deep %d\n", class_sub_deep);
/* Delete Current Class Name Running */
memset(¤tClass, '\0', sizeof(currentClass));
}
void InterpreterClassParam( int progType, int endSub, char className[MAX_STRING_LEN] )
{
int i=0;
VAL_LABEL valdat, datx;
char ident[MAX_STRING_LEN];
memset(&valdat, '\0', sizeof(valdat));
memset(&datx, '\0', sizeof(datx));
memset(&ident, '\0', sizeof(ident));
if(progType == 2 ) {
/* Do as class function Parameter subtitution Program */
pg.pt = 0;
pg.back_pt = 0;
/* throw out '{' symbol */
getlex();
getlex();
if(strncmp(lex.detail.string , "}", 1) == 0)
return;
ungetlex();
// printf("class func param src: %s\n", pg.source);
do{
// first ident
getlex();
// printf("type %d ident: %s\n", lex.type, lex.detail.string);
if(lex.type == TYPE_OBJECT) {
// keep first ident in memory
memset(&ident, '\0', sizeof(ident));
sprintf(ident, "%s", lex.detail.string);
// get equal sym
getlex();
// printf("ident: %s\n", lex.detail.string);
if( lex.type == _EOF )
Error("interupsi yang tidak diinginkan");
if( lex.detail.symbol != '=' )
Error("ident salah masukan");
// get value
getlex();
// printf("lex detail ident : %s\n", lex.detail.ident);
// printf("lex type : %d\n", lex.type);
if(lex.type == TYPE_NUM) {
datx.val = lex.detail.num;
datx.datatype = 0;
} else if(lex.type == TYPE_DBL) {
datx.floatdata = lex.detail.dblnum;
datx.datatype = 1;
} else if(lex.type == TYPE_STR) {
if(lex.detail.string != '\0' && strlen(lex.detail.string) > 0) {
strcpy(datx.str , lex.detail.string);
} else {
strcpy(datx.str , "");
}
datx.datatype = 3;
} else if(lex.type == TYPE_IDENT) {
// printf("ident val : %s\n", lex.detail.ident);
valdat = ValLabel( lex.detail.ident, class_sub_deep, valdat, VAL_FLAG_SEARCH_R );
//ungetlex();
//ungetlex();
//valdat = Factor();
// printf("get value datatype :%d , val : %d \n", valdat.datatype, valdat.val);
datx = valdat;
datx.datatype = valdat.datatype;
}
//printf("saving class obj name: %s\n", ident);
//printf("saving type ...%d\n", datx.datatype);
//printf("saving value ...%d\n", datx.val);
//printf("saving dbl ...%f\n", datx.floatdata);
// save ident
ValLabel( ident, class_sub_deep, datx, VAL_FLAG_SEARCH_W );
}
}while( lex.type != _EOF && strncmp(lex.detail.string , "}", 1) != 0 );
}
}