资源简介

编译原理课设,已实现词法分析和语法分析,代码注释详细,验证无误。

资源截图

代码片段和文件信息

#include“ACTION_GO.h“

stack state;//状态栈
stack symbol;//符号栈
queue inputString;//输入符号串

Action action[50][50];
int Goto[50][50];

char Formula[25][25] = { ‘\0‘ };//文法产生式
char VT[30] = { ‘\0‘ };//终结符
char VN[30] = { ‘\0‘ };//非终结符

void get_Formula()
{
fstream outfile;
cout << “请输入文法个数“ << endl;
int n = 0;
cin >> n;
cout << “请输入文法“ << endl;
for(int i=0;i {
cin >> Formula[i];
}
establish_VT(n);
esrablish_VN(n);
}

int existence(char *array char a)
{//判断数组中是否存在某个字符
int i = 0;
while (array[i])
{
if (array[i] == a)
{
return i;    //存在则返回字符在数组中的位置
 //break;
}
i++;
}
return -1;          //不存在则返回-1
}

void addTocollection(char *array char a)
{//将某个字符加入到字符串的最后
if (existence(array a) == -1)
{//判断是否存在
int i = 0;
while (array[i])
{
++i;
}
array[i] = a;
}
}

void establish_VT(int n)
{//终结符汇总
int i = 1 j;
for (i = 0; i < n; i++)
{
j = 3;
while (Formula[i][j])
{
if ((existence(VT Formula[i][j]) == -1) && Formula[i][j] == ‘a‘&& Formula[i][j + 1] == ‘n‘&& Formula[i][j + 2] == ‘d‘)
{//and
addTocollection(VT Formula[i][j]);
//addTocollection(VT Formula[i][j + 1]);
j+=2;
}
if ((existence(VT Formula[i][j]) == -1|| existence(VT Formula[i][j+1]) == -1) && Formula[i][j] == ‘i‘&& Formula[i][j + 1] == ‘d‘)
{//id
addTocollection(VT Formula[i][j + 1]);   //d
//addTocollection(VT Formula[i][j + 1]);
j++;
}
else if ((existence(VT Formula[i][j]) == -1) && Formula[i][j] == ‘b‘&& Formula[i][j + 1] == ‘e‘&& Formula[i][j + 2] == ‘g‘&& Formula[i][j + 3] == ‘i‘&& Formula[i][j + 4] == ‘n‘)
{//begin
addTocollection(VT Formula[i][j]);
j+=4;
}
else if ((existence(VT Formula[i][j]) == -1) && Formula[i][j] == ‘e‘&& Formula[i][j + 1] == ‘n‘&& Formula[i][j + 2] == ‘d‘)
{//end
addTocollection(VT Formula[i][j]);
j+=2;
}
else if ((existence(VT Formula[i][j]) == -1) && Formula[i][j] == ‘i‘&& Formula[i][j + 1] == ‘f‘)
{//if
addTocollection(VT Formula[i][j]);
j++;
}
else if ((existence(VT Formula[i][j]) == -1) && Formula[i][j] == ‘t‘&& Formula[i][j + 1] == ‘h‘&& Formula[i][j + 2] == ‘e‘&& Formula[i][j + 3] == ‘n‘)
{//then
addTocollection(VT Formula[i][j]);
j+=3;
}
else if ((existence(VT Formula[i][j]) == -1) && Formula[i][j] == ‘:‘&& Formula[i][j + 1] == ‘=‘)
{//:=
addTocollection(VT Formula[i][j]);
j++;
}
else if ((existence(VT Formula[i][j]) == -1) && Formula[i][j] == ‘o‘&& Formula[i][j + 1] == ‘r‘)
{//or
addTocollection(VT Formula[i][j]);
j++;
}
else if ((existence(VT Formula[i][j]) == -1) && Formula[i][j] == ‘n‘&& Formula[i][j + 1] == ‘o‘&& Formula[i][j + 2] == ‘t‘)
{//not
addTocollection(VT Formula[i][j]);
j+=2;
}
else if ((existence(VT Formula[i][j]) == -1|| existence(VT Formula[i][j+1]) == -1|| existence(VT Formu

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     34816  2018-11-30 14:32  SLR1\.vs\SLR1\v15\.suo

     文件    6725632  2018-11-30 14:32  SLR1\.vs\SLR1\v15\Browse.VC.db

     文件   39714816  2018-11-30 14:32  SLR1\.vs\SLR1\v15\ipch\fe9a398798dfff69.ipch

     文件        536  2018-12-04 19:35  SLR1\ACTION_GO.h

     文件        383  2018-12-02 09:50  SLR1\action_goto.txt

     文件      15819  2018-12-19 17:12  SLR1\creat.cpp

     文件        175  2018-12-04 21:51  SLR1\G.txt

    ..A..H.     47104  2018-12-19 17:15  SLR1\SLR1\.vs\SLR1\v15\.suo

     文件    6332416  2018-12-19 17:15  SLR1\SLR1\.vs\SLR1\v15\Browse.VC.db

     文件   38535168  2018-12-10 19:26  SLR1\SLR1\.vs\SLR1\v15\ipch\AutoPCH\55cb13d335b09910\SLR1.ipch

     文件    3670016  2018-12-19 08:49  SLR1\SLR1\.vs\SLR1\v15\ipch\AutoPCH\8a9cacd2aa601461\WORD3.ipch

     文件    3932160  2018-12-04 19:30  SLR1\SLR1\.vs\SLR1\v15\ipch\AutoPCH\e2a7466ac50f6fc2\WORD.ipch

     文件   38535168  2018-12-19 07:50  SLR1\SLR1\.vs\SLR1\v15\ipch\AutoPCH\f2f07148830f10ed\CREAT.ipch

     文件       2843  2018-12-19 17:10  SLR1\SLR1\action_goto.txt

     文件     222720  2018-12-19 17:11  SLR1\SLR1\Debug\SLR1.exe

     文件   10960832  2018-12-19 17:11  SLR1\SLR1\Debug\SLR1.ilk

     文件    7876608  2018-12-19 17:11  SLR1\SLR1\Debug\SLR1.pdb

     文件         52  2018-12-02 09:17  SLR1\SLR1\G.txt

     文件         52  2018-12-19 08:49  SLR1\SLR1\SLR1\data.txt

     文件     809868  2018-12-19 17:11  SLR1\SLR1\SLR1\Debug\creat.obj

     文件        654  2018-12-19 17:11  SLR1\SLR1\SLR1\Debug\SLR1.log

     文件      28035  2018-12-05 09:14  SLR1\SLR1\SLR1\Debug\SLR1.obj

     文件       2666  2018-12-19 17:11  SLR1\SLR1\SLR1\Debug\SLR1.tlog\CL.command.1.tlog

     文件      30570  2018-12-19 17:11  SLR1\SLR1\SLR1\Debug\SLR1.tlog\CL.read.1.tlog

     文件       5396  2018-12-19 17:11  SLR1\SLR1\SLR1\Debug\SLR1.tlog\CL.write.1.tlog

     文件       1558  2018-12-19 17:11  SLR1\SLR1\SLR1\Debug\SLR1.tlog\link.command.1.tlog

     文件       3220  2018-12-19 17:11  SLR1\SLR1\SLR1\Debug\SLR1.tlog\link.read.1.tlog

     文件        826  2018-12-19 17:11  SLR1\SLR1\SLR1\Debug\SLR1.tlog\link.write.1.tlog

     文件        263  2018-12-19 17:11  SLR1\SLR1\SLR1\Debug\SLR1.tlog\SLR1.lastbuildstate

     文件     257024  2018-12-19 17:11  SLR1\SLR1\SLR1\Debug\vc141.idb

............此处省略34个文件信息

评论

共有 条评论