-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecgStatement.cpp
92 lines (92 loc) · 1.84 KB
/
recgStatement.cpp
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
#include "syntaxAnalys.h"
#include <iostream>
#include "getSym.h"
#include "error.h"
#include "symbolTable.h"
#include "midCode.h"
using namespace std;
int recgStatement(int level) {
int curState = 0;
streampos sp_tmp = sourceFile.tellg();
int n_tmp = curSym.len;
int type_tmp = curSym.getType();
try {
if (recgIf(level) != -E_NOT_THIS) return 0;
if (recgRepeat(level) != -E_NOT_THIS) return 0;
if (curSym.getType() == LCURLY_SYM) {
getSym();
while (true)
{
if (recgStatement(level) == -E_NOT_THIS) break;
}
if (curSym.getType() != RCURLY_SYM) {
MISS_TOKEN;
return 0;
}
getSym();
return 0;
}
if (recgAssign(level) != -E_NOT_THIS) {
if (curSym.getType() != SEMICOL_SYM) {
MISS_TOKEN;
return 0;
}
getSym();
return 0;
}
if (recgRead(level) != -E_NOT_THIS) {
if (curSym.getType() != SEMICOL_SYM) {
MISS_TOKEN;
return 0;
}
getSym();
return 0;
}
if (recgWrite(level) != -E_NOT_THIS) {
if (curSym.getType() != SEMICOL_SYM) {
MISS_TOKEN;
return 0;
}
getSym();
return 0;
}
if (recgReturn(level) != -E_NOT_THIS) {
if (curSym.getType() != SEMICOL_SYM) {
MISS_TOKEN;
return 0;
}
getSym();
return 0;
}
if (recgNFuncCall(level) != -E_NOT_THIS) {
if (curSym.getType() != SEMICOL_SYM) {
MISS_TOKEN;
return 0;
}
getSym();
return 0;
}
if (curSym.getType() == SEMICOL_SYM) {
getSym();
return 0;
}
struct tableNode * result = (struct tableNode *)malloc(sizeof(struct tableNode));
strcpy(result->id.name, TMP_VAR);
if (recgIFuncCall(level, result) != -E_NOT_THIS) {
if (curSym.getType() != SEMICOL_SYM) {
MISS_TOKEN;
return 0;
}
getSym();
return 0;
}
throw E_NOT_THIS;
}
catch (int) {
seekSp(sp_tmp);
backSym(n_tmp, type_tmp);
curChar = sourceFile.get();
getSym();
return -E_NOT_THIS;
}
}