-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPseudo_CodeGenerate.java
More file actions
48 lines (47 loc) · 1.55 KB
/
Pseudo_CodeGenerate.java
File metadata and controls
48 lines (47 loc) · 1.55 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
/*******************************************************
Function: Generate program code from PAD.
Input: PAD.
Output: Program code.
******************************************************/
/* When pass it into a function, all the operation to it
* whith that function will effect the original value, as
* it is address pass*/
String TempCode;
CodeGenerate(beginBlock, TempCode);
CodeGenerate(Block CurrentBlock, String CurrentCode)
{
if(CurrentBlock.NodeType is Process) {
CurrentCode.Append(CurrentBlock.codeBlock);
}
else if(CurrentBlock.NodeType is Selection)
{
Generate branch code as SelectionCode;
for every SubNode in CurrentBlock.SubNodeList do
{
Generate branch code branchCode;
String branchBody;
CodeGenerate(SubNode, branchBody);
Insert branchBody into branchCode;
SelectionCode.Append(branchCode);
}
CurrentBlock.Append(SelectionCode);
}
/*If type is HeadPtr, then process the sub-nodes*/
else if(CurrentBlock.NodeType is HeadPtr)
{
for every SubNode in CurrentBlock.SubNodeList do {
CodeGenerate(SubNode, CurrentCode);
}
}
else if(CurrentBlock.NodeType is Loop)
{
Generate loop code as loopCode;
String loopBody;
for every SubNode in CurrentBlock.SubNodeList do {
CodeGenerate(SubNode, loopBody);
}
insert loopBody into loopCode;
CurrentBlock.Append(loopCode);
}
else return;
}