-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecgParaList.cpp
More file actions
76 lines (75 loc) · 1.86 KB
/
recgParaList.cpp
File metadata and controls
76 lines (75 loc) · 1.86 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
#include <iostream>
#include "syntaxAnalys.h"
#include "getSym.h"
#include "error.h"
#include "symbolTable.h"
#include "midCode.h"
using namespace std;
int recgParaList(int level, struct tableNode * prenode) {
int state = 0;
int type = curSym.getType();
if (type != INT_SYM && type != CHAR_SYM) {
reportError(E_MISS_TOKEN);
char until[2] = { ';','\n' };
skip(until, 2);
state = E_MISS_TOKEN;
}
struct tableNode node;
getSym();
if (curSym.getType() != ID_SYM) {
reportError(E_MISS_TOKEN);
char until[2] = { ';','\n' };
skip(until, 2);
state = E_MISS_TOKEN;
}
node.id.lev = level;
strcpy(node.id.name, curSym.getValueStr());
node.kind = TB_VAR;
node.type = type;
if (state == 0) {
if (Table.insert(node) != 0)
reportError(E_REDEF);
else {
prenode->param[prenode->paramNum] = (struct tableNode*)malloc(sizeof(struct tableNode));;
*(prenode->param[prenode->paramNum]) = node;
prenode->paramNum = prenode->paramNum + 1;
}
}
streampos sp = sourceFile.tellg();
while (true)
{
state = 0;
getSym();
if (curSym.getType() != COMMA_SYM)
break;
getSym();
type = curSym.getType();
if (type != INT_SYM && type != CHAR_SYM) break;
getSym();
if (curSym.getType() != ID_SYM) {
reportError(E_MISS_TOKEN);
char until[2] = { ';','\n' };
skip(until, 2);
state = E_MISS_TOKEN;
}
node.id.lev = level;
strcpy(node.id.name, curSym.getValueStr());
node.kind = TB_VAR;
node.type = type;
if (state == 0) {
if (Table.insert(node) != 0)
reportError(E_REDEF);
else {
prenode->param[prenode->paramNum] = (struct tableNode*)malloc(sizeof(struct tableNode));;
*(prenode->param[prenode->paramNum]) = node;
prenode->paramNum = prenode->paramNum + 1;
}
}
sp = sourceFile.tellg();
}
seekSp(sp);
curChar = sourceFile.get();
cout << "At line " << lineNum << " This is a parameter list!" << endl;
getSym();
return 0;
}