1.完善了语法树可视化图

2.更正了predict集
3.更正了语义分析中形参数量不匹配的问题
4.更正了语义分析中过程分析的错误
This commit is contained in:
不点 小 2022-04-06 22:54:34 +08:00
parent ce066f4a16
commit 3481c4eb76
11 changed files with 473 additions and 148 deletions

View File

@ -82,7 +82,7 @@ void LexicalAnalyzer::getTokenList()
//文件读入
ifstream file;
string inputFile;
inputFile = "text.cpp"; //输入文件名
inputFile = "text.txt"; //输入文件名
file.open(inputFile);
if (!file)
cout << "文件打开失败!";

View File

@ -24,6 +24,7 @@ int indentation; //
ofstream treeFile; //树形文件
FILE* listing;
bool Error;
bool hasTypeK;
//语法树可视化使用变量
int circleX, circleY, circleR; //语法树图形化节点坐标x, y, 半径r
@ -63,6 +64,7 @@ void RecursiveDescentParsing::initial()
procNum = 0;
indentation = 0;
stmlkNum = 2; //值为2但代码段为1。在函数中减为1
hasTypeK = false;
}
void RecursiveDescentParsing::ReadNextToken()
@ -298,7 +300,7 @@ TreeNode* RecursiveDescentParsing::DeclarePart(void)
return pp;
}
//< typeDec > ::= ε | TypeDeclaration
//?< typeDec > ::= ε | TypeDeclaration
TreeNode* RecursiveDescentParsing::TypeDec(void)
{
TreeNode* t = nullptr;
@ -358,7 +360,7 @@ TreeNode* RecursiveDescentParsing::TypeDecList(void)
return t;
}
//< typeDecMore > ::= ε | TypeDecList
//?< typeDecMore > ::= ε | TypeDecList
TreeNode* RecursiveDescentParsing::TypeDecMore(void)
{
TreeNode* t = nullptr;
@ -389,7 +391,7 @@ void RecursiveDescentParsing::TypeId(TreeNode* t)
}
}
//< typeName > ::= baseType | structureType | id
//?< typeName > ::= baseType | structureType | id
void RecursiveDescentParsing::TypeName(TreeNode* t)
{
if (t != nullptr)
@ -413,7 +415,7 @@ void RecursiveDescentParsing::TypeName(TreeNode* t)
}
}
//< baseType > ::= INTEGER | CHAR
//?< baseType > ::= INTEGER | CHAR
void RecursiveDescentParsing::BaseType(TreeNode* t)
{
if (t != nullptr)
@ -437,7 +439,7 @@ void RecursiveDescentParsing::BaseType(TreeNode* t)
}
}
//< structureType > ::= arrayType | recType
//?< structureType > ::= arrayType | recType
void RecursiveDescentParsing::StructureType(TreeNode* t)
{
if (t != nullptr)
@ -645,7 +647,7 @@ TreeNode* RecursiveDescentParsing::VarDecList(void)
return t;
}
//< varDecMore > ::= ε | varDecList
//?< varDecMore > ::= ε | varDecList
TreeNode* RecursiveDescentParsing::VarDecMore(void)
{
TreeNode* t = nullptr;
@ -678,7 +680,7 @@ void RecursiveDescentParsing::VarIdList(TreeNode* t)
VarIdMore(t);
}
//< varIdMore > ::= ε | , varIdList
//?< varIdMore > ::= ε | , varIdList
void RecursiveDescentParsing::VarIdMore(TreeNode* t)
{
if (token.word.Lex == SEMI){}
@ -695,7 +697,7 @@ void RecursiveDescentParsing::VarIdMore(TreeNode* t)
}
}
//< procDec > ::= ε | procDeclaration
//?< procDec > ::= ε | procDeclaration
TreeNode* RecursiveDescentParsing::ProcDec(void)
{
TreeNode* t = nullptr;
@ -780,7 +782,7 @@ TreeNode* RecursiveDescentParsing::ParamDecList(void)
return t;
}
//< paramMore > ::= ε | ; paramDecList
//?< paramMore > ::= ε | ; paramDecList
TreeNode* RecursiveDescentParsing::ParamMore(void)
{
TreeNode* t = nullptr;
@ -801,7 +803,7 @@ TreeNode* RecursiveDescentParsing::ParamMore(void)
return t;
}
//< param > ::= typeName formList | VAR typeName formList
//?< param > ::= typeName formList | VAR typeName formList
TreeNode* RecursiveDescentParsing::Param(void)
{
TreeNode* t = new TreeNode;
@ -1009,11 +1011,11 @@ TreeNode* RecursiveDescentParsing::StmList(void)
return t;
}
//?< stmMore > ::= ε | ; stmList ???END,ENDWH,FI,ELSE
//?< stmMore > ::= ε | ; stmList
TreeNode* RecursiveDescentParsing::StmMore(void)
{
TreeNode* t = nullptr;
if (token.word.Lex == END || token.word.Lex == ENDWH){}
if (token.word.Lex == FI || token.word.Lex == ELSE || token.word.Lex == END || token.word.Lex == ENDWH){}
else if (token.word.Lex == SEMI)
{
match(SEMI);
@ -1059,11 +1061,11 @@ TreeNode* RecursiveDescentParsing::Stm(void)
return t;
}
//< assCall > ::= assignmentRest {:=,LMIDPAREN,DOT} | callStmRest {(} ???LMIDPAREN,DOT
//?< assCall > ::= assignmentRest {:=,LMIDPAREN,DOT} | callStmRest {(}
TreeNode* RecursiveDescentParsing::AssCall(void)
{
TreeNode* t = nullptr;
if (token.word.Lex == ASSIGN)
if (token.word.Lex == ASSIGN || token.word.Lex == DOT || token.word.Lex == LMIDPAREN)
t = AssignmentRest();
else if (token.word.Lex == LPAREN)
t = CallStmRest();
@ -1358,7 +1360,7 @@ TreeNode* RecursiveDescentParsing::ActParamList(void)
{
TreeNode* t = nullptr;
if (token.word.Lex == RPAREN) {}
else if (token.word.Lex == ID || token.word.Lex == INTC)
else if (token.word.Lex == ID || token.word.Lex == INTC || token.word.Lex == LPAREN)
{
t = Exp();
if (t != nullptr)
@ -1431,7 +1433,6 @@ TreeNode* RecursiveDescentParsing::Exp(void)
return t;
}
//< simple_exp > ::= term | PlusOp term
TreeNode* RecursiveDescentParsing::Simple_exp(void)
{
TreeNode* t = Term();
@ -1593,7 +1594,7 @@ TreeNode* RecursiveDescentParsing::Variable(void)
return t;
}
//variMore ::= ε
//?variMore ::= ε
// | [exp]
// | . fieldvar
void RecursiveDescentParsing::VariMore(TreeNode* t)
@ -1686,8 +1687,8 @@ void RecursiveDescentParsing::FieldvarMore(TreeNode* t)
void RecursiveDescentParsing::printTree(TreeNode* tree)
{
//fopen_s(&listing, "treeFile.txt", "w");
if (Error == false)
{
//if (Error == false)
//{
indentation += 4; //缩进加4
while (tree != nullptr)
@ -2054,6 +2055,7 @@ void RecursiveDescentParsing::printTree(TreeNode* tree)
line(circleX, circleY - 40, 610, 50);
lastNode = tree->nodekind;
lastIsDeck = false;
hasTypeK = true;
}
break;
@ -2067,7 +2069,10 @@ void RecursiveDescentParsing::printTree(TreeNode* tree)
circleX = 450, circleY = 150, circleR = 40;
circle(circleX, circleY, circleR); // 画圆
outtextxy(circleX - 20, circleY - 10, temp);// 文字
if(hasTypeK == true)
line(circleX - 40, circleY, 290, 150);
else
line(circleX, circleY - 40, 610, 50);
lastNode = tree->nodekind;
lastIsDeck = false;
}
@ -2097,8 +2102,6 @@ void RecursiveDescentParsing::printTree(TreeNode* tree)
circleX = 250, circleY = 550, circleR = 40;
circle(circleX, circleY, circleR); // 画圆
outtextxy(circleX - 30, circleY - 10, temp);// 文字
_stprintf_s(temp, _T("%s"), tree->name[0].c_str());
outtextxy(circleX - 10, circleY + 7, temp);
line(circleX, circleY - 40, 650, 190);
lastX = circleX + 40;
lastY = circleY;
@ -2110,8 +2113,6 @@ void RecursiveDescentParsing::printTree(TreeNode* tree)
circleX = lastX + 60, circleY = lastY, circleR = 40;
circle(circleX, circleY, circleR); // 画圆
outtextxy(circleX - 30, circleY - 10, temp);// 文字
_stprintf_s(temp, _T("%s"), tree->name[0].c_str());
outtextxy(circleX - 10, circleY + 7, temp);
line(circleX - 40, circleY, lastX, lastY);
lastX = circleX + 40;
lastY = circleY;
@ -2210,7 +2211,7 @@ void RecursiveDescentParsing::printTree(TreeNode* tree)
break;
case CallK:
treeFile << "Call "; break;
treeFile << "Call ";
treeFile << tree->name[0] << " ";
_stprintf_s(temp, _T("Call"));
if (stmlkNum == 1)
@ -2327,8 +2328,8 @@ void RecursiveDescentParsing::printTree(TreeNode* tree)
tree = tree->sibling;
}
indentation -= 4; //缩进减4
}
else
treeFile << "存在语法错误,语法树生成失败!";
//}
//else
// treeFile << "存在语法错误,语法树生成失败!";
//fclose(listing);
}

View File

@ -29,8 +29,8 @@ void SemanticAnalysis::initial()
scope[i] = NULL;
scopeLevel = -1;
hasError = false;
errorFile.open("parseError.txt", ios::out | ios::app);
errorFile.open("symbTable.txt");
errorFile.open("semanticError.txt");
tableFile.open("symbTable.txt");
intPtr = NewTy(intTy);
charPtr = NewTy(charTy);
@ -39,6 +39,7 @@ void SemanticAnalysis::initial()
void SemanticAnalysis::fileClose()
{
tableFile.close();
errorFile.close();
}
@ -510,6 +511,7 @@ void SemanticAnalysis::varDecList(TreeNode* t)
{
//Kind为变量类型
attrIr.kind = varKind;
//循环处理同一个节点的id调用类型处理函数
for (int i = 0; i < t->idnum; i++)
{
@ -522,6 +524,8 @@ void SemanticAnalysis::varDecList(TreeNode* t)
attrIr.More.VarAttr.access = dir;
attrIr.More.VarAttr.level = scopeLevel;
attrIr.More.VarAttr.off = Off;
if (attrIr.idtype != NULL)
Off = Off + attrIr.idtype->size;
}//偏移加变量类型的size
@ -543,8 +547,8 @@ void SemanticAnalysis::varDecList(TreeNode* t)
entry = NULL;
}
else
t->table[i] = entry;
//记录类型名
t->table[i] = entry;
}
t = t->sibling;
}
@ -555,6 +559,7 @@ void SemanticAnalysis::varDecList(TreeNode* t)
void SemanticAnalysis::procDecPart(TreeNode* t)
{
SymbTable* entry = HeadProcess(t);
TreeNode* temp = t;
t = t->child[1];
while (t != NULL)
{
@ -577,6 +582,9 @@ void SemanticAnalysis::procDecPart(TreeNode* t)
t = t->sibling;
}
t = temp;
Body(t->child[2]);
//结束当前scope
DestroyTable();
}
@ -597,12 +605,13 @@ SymbTable* SemanticAnalysis::HeadProcess(TreeNode* t)
t->table[0] = entry;
//调用形参处理函数
if (entry != nullptr)
entry->attrIR.More.ProcAttr.param = ParaDecList(t);
return entry;
}
//?
//?形参分析处理函数
ParamTable* SemanticAnalysis::ParaDecList(TreeNode* t)
{
TreeNode* p = NULL;
@ -617,14 +626,36 @@ ParamTable* SemanticAnalysis::ParaDecList(TreeNode* t)
//调用函数varDecPart
varDecList(p);
//?需要循环吗
//?需要循环吗
//构造形参符号表
SymbTable* temp = scope[scopeLevel];
ParamTable* Ptemp;//符号表
Ptemp = NewParam();
Ptemp->entry = temp;
Ptemp->next = NULL;
result = Ptemp;
ParamTable* Pcurrent = NULL;//符号表
ParamTable* Plast = NULL;//符号表
while (temp != NULL)
{
Pcurrent = NewParam();
//第一个形参
if (result == NULL)
{
result = Pcurrent;
Plast = Pcurrent;
}
//确认形参类型
temp->attrIR.More.VarAttr.isParam = true;
Pcurrent->entry = temp;
Pcurrent->next = NULL;
//把该符号表连接到链表上
if (Plast != Pcurrent)
{
Plast->next = Pcurrent;
Plast = Pcurrent;
}
temp = temp->next;
}
}
return result;
@ -777,10 +808,10 @@ TypeIR* SemanticAnalysis::arrayVar(TreeNode* t)
{
TypeIR* Eptr = NULL;
SymbTable* entry = NULL;
if (FindEntry(t->name[0], &entry))
if (!FindEntry(t->name[0], &entry))
{
string temp = t->name[0].c_str();
semanticError(t->lineno, temp + "未找到此标识符");
semanticError(t->lineno, temp + " 声明缺失");
entry = NULL;
}
else
@ -792,7 +823,7 @@ TypeIR* SemanticAnalysis::arrayVar(TreeNode* t)
}
else
{
if (entry->attrIR.idtype != NULL)
if (entry->attrIR.idtype == NULL)
{
string temp = t->name[0].c_str();
semanticError(t->lineno, temp + " 不是数组变量");
@ -828,7 +859,7 @@ TypeIR* SemanticAnalysis::recordVar(TreeNode* t)
if (FindEntry(t->name[0], &entry) == false)
{
string temp = t->name[0].c_str();
semanticError(t->lineno, temp + "未找到此标识符");
semanticError(t->lineno, temp + " 声明缺失");
}
else
{
@ -886,10 +917,10 @@ void SemanticAnalysis::assignstatement(TreeNode* t)
if (child1->child[0] == NULL)
{
if (FindEntry(t->name[0], &entry) == false)
if (FindEntry(t->child[0]->name[0], &entry) == false)
{
string temp = t->name[0].c_str();
semanticError(t->lineno, temp + "未找到此标识符");
string temp = t->child[0]->name[0].c_str();
semanticError(t->lineno, temp + " 声明缺失");
entry = NULL;
}
else
@ -931,24 +962,28 @@ void SemanticAnalysis::callstatement(TreeNode* t)
if (temp == false)
{
string temp = t->name[0].c_str();
semanticError(t->lineno, temp + "未找到此函数");
semanticError(t->lineno, temp + " 函数未声明");
}
else
{
ParamTable* tempTable = entry->attrIR.More.ProcAttr.param;
if (entry->attrIR.kind != procKind)
{
string temp = t->name[0].c_str();
semanticError(t->lineno, temp + " 不是函数名");
}
//判断形参实参对应
//参数表指针
else
{
//参数表指针
ParamTable* tempTable = entry->attrIR.More.ProcAttr.param;
SymbTable* paraEntry = tempTable->entry;
//实参指针
TreeNode* pNode = t->child[1];
while (tempTable != NULL && pNode != NULL)
while ((paraEntry != NULL && paraEntry->attrIR.More.VarAttr.isParam != false) && pNode != NULL)
{
AccessKind tempA;
TypeIR* tempT = Expr(pNode, &tempA);
@ -960,11 +995,14 @@ void SemanticAnalysis::callstatement(TreeNode* t)
semanticError(t->lineno, "参数类型不匹配");
pNode = pNode->sibling;
tempTable = tempTable->next;
paraEntry = paraEntry->next;
}
//参数数量不匹配
if (tempTable != NULL || pNode != NULL)
if (pNode != NULL)
semanticError(t->lineno, "参数个数不匹配");
if(paraEntry != NULL && paraEntry->attrIR.More.VarAttr.isParam != false)
semanticError(t->lineno, "参数个数不匹配");
}
@ -1026,7 +1064,7 @@ void SemanticAnalysis::readstatement(TreeNode* t)
if (FindEntry(t->name[0], &entry) == false)
{
string temp = t->name[0].c_str();
semanticError(t->lineno, temp + "未找到此标识符");
semanticError(t->lineno, temp + " 声明缺失");
}
else
if (entry->attrIR.kind != varKind)
@ -1041,6 +1079,7 @@ void SemanticAnalysis::writestatement(TreeNode* t)
{
TypeIR* Etp = Expr(t->child[0], NULL);
if (Etp != NULL)
if (Etp->kind == boolTy)
semanticError(t->lineno, "表达式不合法");
}

View File

@ -1,27 +1,111 @@
ProK
PheadK p
TypeK
line: 2 Deck Integer t
line: 3 Deck Chark c
PheadK bubble
VarK
line: 4 Deck Integer v7 v8
line: 5 Deck Chark v9
line: 6 Deck Integer v4
line: 2 Deck Integer i j num
line: 3 Deck ArrayK 20 1 Integer a
line: 5 ProcDecK q
line: 5 Deck value param: Integer num
VarK
line: 7 Deck Integer i j k
line: 8 Deck Integer t
StmLk
line: 8 Stmtk Assign
line: 8 ExpK Vari Id v1
line: 8 ExpK Op +
line: 8 ExpK Vari Id v2
line: 8 ExpK Const Id 10
line: 9 Stmtk Assign
line: 9 ExpK Vari Id v3
line: 9 ExpK Op +
line: 9 ExpK Vari Id v4
line: 9 ExpK Vari Id v5
line: 10 Stmtk Assign
line: 10 ExpK Vari Id v6
line: 10 ExpK Op +
line: 10 ExpK Const Id 10
line: 10 ExpK Const Id 10
line: 11 Stmtk Write
line: 11 ExpK Vari Id v1
line: 10 ExpK Vari Id i
line: 10 ExpK Const Id 1
line: 11 Stmtk While
line: 11 ExpK Op <
line: 11 ExpK Vari Id i
line: 11 ExpK Vari Id num
line: 12 Stmtk Assign
line: 12 ExpK Vari Id j
line: 12 ExpK Op +
line: 12 ExpK Op -
line: 12 ExpK Vari Id num
line: 12 ExpK Vari Id i
line: 12 ExpK Const Id 1
line: 13 Stmtk Assign
line: 13 ExpK Vari Id k
line: 13 ExpK Const Id 1
line: 14 Stmtk While
line: 14 ExpK Op <
line: 14 ExpK Vari Id k
line: 14 ExpK Vari Id j
line: 15 Stmtk If
line: 15 ExpK Op <
line: 15 ExpK Vari ArrayMember a
line: 15 ExpK Op +
line: 15 ExpK Vari Id k
line: 15 ExpK Const Id 1
line: 15 ExpK Vari ArrayMember a
line: 15 ExpK Vari Id k
line: 17 Stmtk Assign
line: 17 ExpK Vari Id t
line: 17 ExpK Vari ArrayMember a
line: 17 ExpK Vari Id k
line: 18 Stmtk Assign
line: 18 ExpK Vari ArrayMember a
line: 18 ExpK Vari Id k
line: 18 ExpK Vari ArrayMember a
line: 18 ExpK Op +
line: 18 ExpK Vari Id k
line: 18 ExpK Const Id 1
line: 19 Stmtk Assign
line: 19 ExpK Vari ArrayMember a
line: 19 ExpK Op +
line: 19 ExpK Vari Id k
line: 19 ExpK Const Id 1
line: 19 ExpK Vari Id t
line: 20 Stmtk Assign
line: 20 ExpK Vari Id t
line: 20 ExpK Const Id 0
line: 22 Stmtk Assign
line: 22 ExpK Vari Id k
line: 22 ExpK Op +
line: 22 ExpK Vari Id k
line: 22 ExpK Const Id 1
line: 24 Stmtk Assign
line: 24 ExpK Vari Id i
line: 24 ExpK Op +
line: 24 ExpK Vari Id i
line: 24 ExpK Const Id 1
StmLk
line: 29 Stmtk Read num
line: 30 Stmtk Assign
line: 30 ExpK Vari Id i
line: 30 ExpK Const Id 1
line: 31 Stmtk While
line: 31 ExpK Op <
line: 31 ExpK Vari Id i
line: 31 ExpK Op +
line: 31 ExpK Vari Id num
line: 31 ExpK Const Id 1
line: 32 Stmtk Read j
line: 33 Stmtk Assign
line: 33 ExpK Vari ArrayMember a
line: 33 ExpK Vari Id i
line: 33 ExpK Vari Id j
line: 34 Stmtk Assign
line: 34 ExpK Vari Id i
line: 34 ExpK Op +
line: 34 ExpK Vari Id i
line: 34 ExpK Const Id 1
line: 36 Stmtk Call
line: 36 ExpK Vari Id q
line: 36 ExpK Vari Id num
line: 37 Stmtk Assign
line: 37 ExpK Vari Id i
line: 37 ExpK Const Id 1
line: 38 Stmtk While
line: 38 ExpK Op <
line: 38 ExpK Vari Id i
line: 38 ExpK Op +
line: 38 ExpK Vari Id num
line: 38 ExpK Const Id 1
line: 39 Stmtk Write
line: 39 ExpK Vari ArrayMember a
line: 39 ExpK Vari Id i
line: 40 Stmtk Assign
line: 40 ExpK Vari Id i
line: 40 ExpK Op +
line: 40 ExpK Vari Id i
line: 40 ExpK Const Id 1

0
semanticError.txt Normal file
View File

12
symbTable.txt Normal file
View File

@ -0,0 +1,12 @@
==========µÚ0²ã·ûºÅ±í==========
i: intTy varKind Level: 0 Offset: 7 indir
j: intTy varKind Level: 0 Offset: 8 indir
num: intTy varKind Level: 0 Offset: 9 indir
a: arrayTy varKind Level: 0 Offset: 10 indir
q: funcKind Level: 1 nOff: -842150656
==========µÚ1²ã·ûºÅ±í==========
num: intTy varKind Level: 1 Offset: 7 dir
i: intTy varKind Level: 1 Offset: 8 indir
j: intTy varKind Level: 1 Offset: 9 indir
k: intTy varKind Level: 1 Offset: 10 indir
t: intTy varKind Level: 1 Offset: 11 indir

View File

@ -1,12 +0,0 @@
program p
type t = integer;
c = char;
var integer v7,v8;
char v9;
integer v4;
begin
v1:= v2 + 10;
v3:= v4 + v5;
v6:= 10 + 10;
write(v1)
end.

42
text.txt Normal file
View File

@ -0,0 +1,42 @@
program bubble
var integer i,j,num;
array [1..20] of integer a;
procedure q(integer num);
var integer i,j ,k;
integer t;
begin
i:=1;
while i < num do
j := num-i+ 1;
k:=1;
while k<j do
if a[k+ 1] < a[k]
then
t:=a[k ];
a[k] :=a[k+ 1 ];
a[k+ 1 ]:=t
else t:=0
fi;
k:=k+ 1
endwh;
i:=i+1
endwh
end
begin
read(num);
i:=1;
while i <(num+ 1) do
read(j);
a[i]:=j;
i:=i+1
endwh;
q(num);
i:=1;
while i <(num+ 1) do
write(a[i]);
i:=i+1
endwh
end.

View File

@ -10,9 +10,11 @@
#include <graphics.h>
#include"LexicalAnalyzer.h"
#include"Parsing_RD.h"
#include"SemanticAnalysis.h"
using namespace std;
int main()
{
/*======词法分析=====*/
LexicalAnalyzer lexicalanalyzer;
lexicalanalyzer.getTokenList();
int count = lexicalanalyzer.TokenList.size();
@ -25,6 +27,7 @@ int main()
// << ">" << endl;
//}
/*=====语法分析=====*/
ofstream file;
file.open("tokenList.txt");
for (int i = 0; i < count; i++)
@ -51,8 +54,15 @@ int main()
rd.printTree(root);
saveimage(_T("treeFile.bmp"));
}
closegraph();
rd.fileClose();
/*=====语义分析=====*/
SemanticAnalysis sa;
sa.initial();
sa.analyze(root);
sa.PrintSymbTable();
sa.fileClose();
cout << "ÔËÐгɹ¦" << endl;
}

View File

@ -1,49 +1,198 @@
1 2 program
1 23 p
2 4 type
2 23 t
2 27 =
1 23 bubble
2 5 var
2 21 integer
2 23 i
2 38 ,
2 23 j
2 38 ,
2 23 num
2 37 ;
3 23 c
3 27 =
3 22 char
3 17 array
3 39 [
3 24 1
3 41 ..
3 24 20
3 40 ]
3 18 of
3 21 integer
3 23 a
3 37 ;
4 5 var
4 21 integer
4 23 v7
4 38 ,
4 23 v8
4 37 ;
5 22 char
5 23 v9
5 3 procedure
5 23 q
5 33 (
5 21 integer
5 23 num
5 34 )
5 37 ;
6 21 integer
6 23 v4
6 37 ;
7 13 begin
8 23 v1
8 26 :=
8 23 v2
8 29 +
8 24 10
7 5 var
7 21 integer
7 23 i
7 38 ,
7 23 j
7 38 ,
7 23 k
7 37 ;
8 21 integer
8 23 t
8 37 ;
9 23 v3
9 26 :=
9 23 v4
9 29 +
9 23 v5
9 37 ;
10 23 v6
9 13 begin
10 23 i
10 26 :=
10 24 10
10 29 +
10 24 10
10 24 1
10 37 ;
11 16 write
11 33 (
11 23 v1
11 34 )
12 14 end
12 35 .
13 0 ÿ
11 10 while
11 23 i
11 28 <
11 23 num
11 11 do
12 23 j
12 26 :=
12 23 num
12 30 -
12 23 i
12 29 +
12 24 1
12 37 ;
13 23 k
13 26 :=
13 24 1
13 37 ;
14 10 while
14 23 k
14 28 <
14 23 j
14 11 do
15 6 if
15 23 a
15 39 [
15 23 k
15 29 +
15 24 1
15 40 ]
15 28 <
15 23 a
15 39 [
15 23 k
15 40 ]
16 7 then
17 23 t
17 26 :=
17 23 a
17 39 [
17 23 k
17 40 ]
17 37 ;
18 23 a
18 39 [
18 23 k
18 40 ]
18 26 :=
18 23 a
18 39 [
18 23 k
18 29 +
18 24 1
18 40 ]
18 37 ;
19 23 a
19 39 [
19 23 k
19 29 +
19 24 1
19 40 ]
19 26 :=
19 23 t
20 8 else
20 23 t
20 26 :=
20 24 0
21 9 fi
21 37 ;
22 23 k
22 26 :=
22 23 k
22 29 +
22 24 1
23 12 endwh
23 37 ;
24 23 i
24 26 :=
24 23 i
24 29 +
24 24 1
25 12 endwh
26 14 end
28 13 begin
29 15 read
29 33 (
29 23 num
29 34 )
29 37 ;
30 23 i
30 26 :=
30 24 1
30 37 ;
31 10 while
31 23 i
31 28 <
31 33 (
31 23 num
31 29 +
31 24 1
31 34 )
31 11 do
32 15 read
32 33 (
32 23 j
32 34 )
32 37 ;
33 23 a
33 39 [
33 23 i
33 40 ]
33 26 :=
33 23 j
33 37 ;
34 23 i
34 26 :=
34 23 i
34 29 +
34 24 1
35 12 endwh
35 37 ;
36 23 q
36 33 (
36 23 num
36 34 )
36 37 ;
37 23 i
37 26 :=
37 24 1
37 37 ;
38 10 while
38 23 i
38 28 <
38 33 (
38 23 num
38 29 +
38 24 1
38 34 )
38 11 do
39 16 write
39 33 (
39 23 a
39 39 [
39 23 i
39 40 ]
39 34 )
39 37 ;
40 23 i
40 26 :=
40 23 i
40 29 +
40 24 1
41 12 endwh
42 14 end
42 35 .
42 0 ÿ

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 MiB

After

Width:  |  Height:  |  Size: 3.2 MiB