-
Notifications
You must be signed in to change notification settings - Fork 0
/
getDeclaration.cpp
64 lines (38 loc) · 1.1 KB
/
getDeclaration.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
#include "Declaration.h"
#include "Statement.h"
#include "Expression.h"
Declaration * Declaration::getDeclaration()
{
Declaration * result = nullptr;
char *var1, *var2;
Expression * var3 = nullptr;
deque<Declaration*> * params = nullptr;
deque<Element*> * elements = nullptr;
if (var1 = Minst->GetName(false)) {
var2 = Minst->GetName(true);
if (Minst->Match("(")) {
params = new deque<Declaration*>();
Declaration* tmp = nullptr;
while (tmp = Declaration::getParameter(var2)) {
params->push_back(tmp);
if (!Minst->Match(","))
break;
}
Minst->Matching(")");
Minst->Matching("{");
Element * element;
elements = new deque<Element*>();
while ((element = Statement::getStatement(params)) || (element = Expression::getExpression(true, params)))
elements->push_back(element);
Minst->Matching("}");
result = new Declaration(var1, var2, params, elements);
}
else {
if (Minst->Match("="))
var3 = Expression::getExpression(false, nullptr);
result = new Declaration(var1, var2, var3);
Minst->Matching(";");
}
}
return result;
}