Расчёт (комплексная лаба) Построение метрики уровня языка программирования / МССвИР_отчет
.pdfBecomes active after code opening. Performs the code analyzing with result - PLL of this program shown as a MessageBox. This parameter may vary in interval [0,10].
-Create Database
Creates a DB file (*.PLL), which will contain PLL values of several measurings. The data in such files is stored like following script:
totallines=N
PLL=B
C1
C2
...
CN
where N is number of measurements, information about their results is stored in values C1..CN; B is average PLL level for this DB.
-Open Result Database
Opens an existing DB file (*.PLL), which will contain PLL values of several measurings. The PLL coefficient is shown after "Open Result DB" action.
-Add To Database
Adds the current calculated PLL to opened DB. The average PLL quotient is recalculated taking the inserted value into consideration, and the result is shown and added to *.PLL file.
-Close Database
Closes opened current DB. The handle is destroyed and for adding a new item you should reopen existing DB or create a new one.
-Close Source Code
Closes the *.Pas file and cleanes the screen, preparing the program for following calculations. -Exit
Closes the application. Help menu
-Metrics Help
Shows this information. -About.
Shows brief information about the program and the developer. Have fun!
---------
V.L. Kasperovich, 28.11.2010 16:24
11
Рис. 3.6. Интерфейс справочной системы программы PLLM
12
4. Выводы
При использовании данной программы были проведены статистические исследования уровня языка программирования Pascal. Полученные результаты показывают, что средний уровень ЯП Pascal лежит в интервале [2,15..2,45]. Это довольно высокоуровневый язык (его уровень выше, чем, например PL/1 (1,53), но ниже, чем у современных объектноориентированных языков программирования, таких, как C#, Delphi или С++). Уровень языка программирования Pascal показывает его универсальность: при наличии всего около 200 имплиментарных функций данный ЯП пригоден для решения довольно широкого круга проблем. Учитывая, что Pascal был создан как язык для обучения основам алгоритмизации и программирования, такой высокий уровень может быть обусловлен также тем, что для исследования были использованы учебные программы, для написания которых встроенных средств данного языка было вполне достаточно.
При исследовании уровень языка колебался в пределах от 0,163 до 23,358 для различных программ. Это обусловлено причинами, изложенными в п.2, в частности, нестабильностью данной метрики и не инвариантностью еѐ по отношению к разным программам.
13
5. Литература
1.Бахтизин В.В., Глухова Л.А. Стандартизация и сертификация программного обеспечения: Учеб. пособие. – Мн.: БГУИР, 2006.
2.Глухова Л.А. Электронный учебно-методический комплекс «Метрология, стандартизация и сертификация в информатике и радиоэлектронике» для студентов специальности I-40 01 01 Программное обеспечение информационных технологий: Учеб. пособие. – Мн.: БГУИР, 2009.
3.Изосимов А.В., Рыжко А.Л. Метрическая оценка качества программ.
– М.: МАИ, 1989.
14
Приложение А. Исходный код главного модуля программы
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data;
using System.Drawing; using System.Text;
using System.Windows.Forms; using System.IO;
namespace Metrics
{
public partial class PLLM : Form
{
string s,filename;
string[] f1 = new string[20]; string[] f2 = new string[30]; string[] f3 = new string[79]; string[] f4 = new string[92];
string[] OpUsedInNativeFuncs = new string[1000]; string[] blocks = new string[6] { "program",
"uses", "const", "var", "type", "label"}; string[] DT = new string[17] {
"shortint","integer","longint","byte","word","real","single","do
uble","extended","comp","char","boolean","string","array","recor d","set","of" };
string[] ReservedWords = new string[8] {"until","array","begin","do","downto","then","end","to" };
char[] Arithm = new char[4] { '-', '/', '+', '*'}; string[] LoadedCode = new string[1000];
string[] dictOperator = new string[10000]; //unique
operators
string[] dictOperand = new string[10000]; //unique
operands
int[] numOperator = new int[10000]; //number of
operators
int[] numOperand = new int[10000];//number of
operands
double[] DBCoefficients = new double[500]; //int[,] blocks = new int[7, 2];//Blocks entrance
and quit (0-program,1-uses,2-label,3-type,4-const,5-var,6- begin..end.)
int codelen,curpos,posnat=0;
int eta1 = 0, eta2 = 0, n1 = 0, n2 = 0, etaR = 0; int numstr,begin_end=0;
double V, Lambda, Vr,CurPLL; bool
comment=false,literal=false,param=false,uses_program=false,proce dure_function=false;
15
FileInfo SrcFile,DBFile;
StreamReader /*fdes,*/DBStream;
public PLLM()
{
InitializeComponent();
}
private void CleanData()
{
int i;
for (i = 0; i <= 999; i++)
{
numOperand[i] = 0; OpUsedInNativeFuncs[i] = ""; numOperator[i] = 0; dictOperand[i] = ""; dictOperator[i] = "";
}
}
private string[] LoadExisting(string pathname,int
len)
{
//crt 20,dos 33, graph 79,system 92
string tmps;
string[] u = new string[100]; FileInfo URF;
StreamReader URF_1; int i;
URF = new FileInfo(pathname); URF_1 = URF.OpenText();
for (i = 0; i <= len-1; i++)
{
tmps = URF_1.ReadLine(); tmps = tmps.ToLower(); u[i] = tmps;
}
URF_1.Close();
return (string[])u.Clone();
}
private void ParseString(string str)
{
int i, j,pos=0;
bool IDFound, exists; string ts="";
char tc=' ',prev=' ';
char[] codestr=new char[128];
16
char[] newID = new char[100]; codestr=str.ToCharArray(); IDFound = false;
for (i = 0; i <= str.Length; i++)
{
prev = tc;
if (i==str.Length) tc=' '; else
tc = codestr[i];
if (Convert.ToInt32(tc) == 39) literal = !(literal);
if (Convert.ToInt32(prev) == 123) comment =
true;
if (Convert.ToInt32(prev) == 125) comment =
false;
if ((!literal) && (!comment))
{
if (Char.IsLetterOrDigit(tc))
{
if ((!(Char.IsLetter(prev))) && (!(Char.IsNumber(prev))) && (Char.IsLetter(tc)))
{
if (Convert.ToInt16(prev) !=
39)
|
IDFound = |
true; |
for |
(j = 0; j |
<= 99; j++) |
|
newID[j] |
= ' '; |
pos |
= 0; |
|
newID[pos] = |
tc; |
}
else
{
pos++; newID[pos] = tc;
}
}
else
{
if ((Char.IsLetterOrDigit(prev)) &&
IDFound)
{
IDFound = false;
ts = new string(newID); ts = ts.Trim();
exists = false;
for (j = 0; j <= curpos - 1;
j++)
if (ts == dictOperand[j])
{
exists = true; numOperand[j]++;
17
}
if
(((!exists)&&(!uses_program))||(procedure_function))
{
dictOperand[curpos] = ts; numOperand[curpos] = 1; curpos++;
}
if ((ts == "uses") || (ts ==
"program"))
uses_program = true;
if ((ts == "procedure") || (ts
== "function"))
{
procedure_function = true; begin_end = 0;
}
if ((ts=="begin")||(ts ==
"case"))
begin_end++; if (ts == "end")
{
begin_end--;
if (begin_end==0) procedure_function =
false;
}
if (param)
{
bool q = false;
for (int l = 0; l <=
posnat-1; l++)
if
(OpUsedInNativeFuncs[l] == ts)
q = true; if (!q)
{
etaR++;
posnat++;
OpUsedInNativeFuncs[posnat - 1] = ts;
}
}
}
switch (tc)
{
case ';':
{
numOperator[0]++; if (uses_program)
18
uses_program =
false;
}
break; case '-':
numOperator[3]++;
break; case '+':
numOperator[4]++;
break; case '*':
numOperator[5]++;
break; case '/':
numOperator[6]++;
break; case '=':
{
if (prev == ':') numOperator[1]++;
else
numOperator[2]++;
break;
}
case '\'': numOperator[7]++; break;
case ',': numOperator[8]++; break;
case '(': numOperator[9]++; if (NativeChk(ts))
param = true; break;
case ')':
param = false; break;
default:
break;
}
}
}
}
}
private void openSourceCodeToolStripMenuItem_Click(object sender, EventArgs e)
{
openSourceCode();
19
}
private void openSourceCode()
{
int i; CleanData();
for (i = 0; i <= 999; i++) LoadedCode[i] = "";
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
richTextBox1.LoadFile(openFileDialog1.FileName,
RichTextBoxStreamType.PlainText); SrcFile = new
FileInfo(openFileDialog1.FileName); analyzeToolStripMenuItem.Enabled = true; closeSourceCodeToolStripMenuItem.Enabled =
true;
saveToolStripButton.Enabled = true; toolStripButton1.Enabled = true; copyToolStripButton.Enabled = true; toolStripButton2.Enabled = true; //fdes = SrcFile.OpenText();
/*
codelen = 0;
s = fdes.ReadLine(); while (s != null)
{
s = s.ToLower(); s = s.Trim();
LoadedCode[codelen] = s; s = fdes.ReadLine(); codelen++;
}
codelen--;*/
}
this.Text = "Programming Language Level Metrics" + " - [" + openFileDialog1.FileName + "]";
}
private void LoadSC()
{
codelen = 0;
s = richTextBox1.Lines[codelen];
while (codelen<=richTextBox1.Lines.Length-1)
{
s = s.ToLower(); s = s.Trim();
LoadedCode[codelen] = s;
s = richTextBox1.Lines[codelen];
20