您好,欢迎来到筏尚旅游网。
搜索
您的当前位置:首页合肥工业大学编译原理实验报告(完整代码版)

合肥工业大学编译原理实验报告(完整代码版)

来源:筏尚旅游网
.

计算机与信息学院 编译原理 实验报告

专 业 班 级学生及学号课程教学班号任 课 教 师实验指导教师实

点2015 ~2016

.

信息安全13-1班 马骏 2013211869 宏芒 宏芒 实验楼机房

学年第 二 学期

.

实验1 词法分析设计

一、 实验目的

通过本实验的编程实践,使学生了解词法分析的任务,掌握词法分析程序设

计的原理和构造方法,使学生对编译的基本概念、原理和方法有完整的和清楚的

理解,并能正确地、熟练地运用 二、 实验要求

1、编程时注意编程风格:空行的使用、注释的使用、缩进的使用等。

2、将标识符填写的相应符号表须提供给编译程序的以后各阶段使用。 3、根据测试数据进行测试。测试实例应包括以下三个部分: 全部合法的输入。 各种组合的非法输入。 由记号组成的句子。

4、词法分析程序设计要求输出形式: 例:输入VC++语言的实例程序: If i=0 then n++; a﹤= 3b %); 输出形式为:

单词 二元序列 类 型 位置(行,列) (单词种别,单词属性)

for (1,for ) 关键字 (1,

.

.

1)

i ( 6,i ) 标识符 (1,2)

= ( 4,= ) 关系运算符 (1,3) 12

0 ( 5,0 ) 常数 (1,4) then ( 1,then) 关键字 (1,5) n (6,n ) 标识符 (1,6) ++ Error Error (1,7) ; ( 2, ; ) 分界符 (1,8)

a (6,a ) 标识符 (2,1)

﹤= (4,<= ) 关系运算符 (2,2) 3b Error Error (2,4) % Error Error (2,4) ) ( 2, ) ) 分界符 (2,5)

; ( 2, ; ) 分界符 (2,6) 三、 实验容

用 VC++/VB/JAVA 语言实现对 C 语言子集的源程序进行词法分析。通过

.

.

入源程序从左到右对字符串进行扫描和分解,依次输出各个单词的部编码及单

词符号自身值;若遇到错误则显示“Error”,然后跳过错误部分继续显示 ;同时

进行标识符登记符号表的管理。 以下是实现词法分析设计的主要工作: (1)从源程序文件中读入字符。

(2)统计行数和列数用于错误单词的定位。 (3)删除空格类字符,包括回车、制表符空格。

(4)按拼写单词,并用(码,属性)二元式表示。(属性值——token的机 表示)

(5)如果发现错误则报告出错 7

(6)根据需要是否填写标识符表供以后各阶段使用。

四、实验步骤

1、根据流程图编写出各个模块的源程序代码上机调试。

2、 编制好源程序后,设计若干用例对系统进行全面的上机测试,并通过所设计 的词法分析程序;直至能够得到完全满意的结果。 3、书写实验报告 ;实验报告正文的容: 功能描述:该程序具有什么功能?

程序结构描述:函数调用格式、参数含义、返回值描述、函数功能;函数

.

.

之间的调用关系图。

详细的算法描述(程序总体执行流程图) 。 给出软件的测试方法和测试结果。

实验总结 (设计的特点、不足、收获与体会)。 五、实验截图

先创建salaryfile.txt文件 输入

If i=0 then n++; a<= 3b %);

六、核心代码

#include #include #include #include using namespace std;

const char* salaryfile=\"salaryfile.txt\";

.

.

const int max=40; string

id[max]={\"do\关键字表 string

s[max]={\,\"<>\分界符表 算数运算符表 关系运算符表 string k[max];// 标识符 string ci[max];// 常数 int fjfpoint=5;//分界符表尾 int mathpoint=9;//算数运算符表尾 int cipointer=0;//常数表尾 int idpointer=0;//关键字表尾 int kpointer=0;//标识符表尾 int fjf;//0 不是分界符 1是

int rowy=1;//识别输入行位置 int rowx=1;//识别输入列位置

int outkey=0;//打印控制 0为数字后有字母 其他可以

void searcht(int i,string m)//根据已识别的首字母识别字符串 {

.

.

// cout<<\"enter searcht!!\"<if(i==0)//首字符是字母识别关键字

{

// cout<<\" a word!!\"<cout<<\"(1,\"<(\"<}

}

if(x==max)//不是关键字再识别标识符 { for(x=0;xif(k[x]==m) {

cout<<\"(6,\"<\"<<\"

(\"<.

字符

.

break;

} }

if(x==max)//标识符表没有时插入标识符 {

cout<<\"(6,\"<\"<<\"

(\"<kpointer++;

}

}

}

if(i==1)//识别常数 {

// cout<<\" a number!!\"<cout<<\"(5,\"<.

.

}

}

break;

if(x==max) {

}

cout<<\"(5,\"<ci[cipointer]=m; cipointer++;

if(i==2)//识别 分界符 算数运算符 关系运算符 {

// cout<<\" a signal!!\"<for(x=0;xif(s[x]==m)

break;

// x--;

if(x<6) {

.

.

fjf=1;

}

if(x>5&&x<10) { if(outkey==1)

{

cout<<\"(3,\"<}

if(x>9&&xcout<<\"(4,\"<fjf=0;

.

关系运

运算符符

.

};

}

}

if(x==max) { }

if(outkey==1) {

cout<<\"Error Error (\"<void wordlook(char t,string sn)//识别首字符,分类识别字符串 {

if(t>=48&&t<=57)

searcht(1,sn);

else {

if((t>&&t<91)||(t>96&&t<123)) searcht(0,sn);

.

.

};

}

else searcht(2,sn);

void split(string s)//分割字符串 {

// cout<if((s[x]>&&s[x]<91)||(s[x]>96&&s[x]<123)||(s[x]>=48&&s[x]<=57)|for(x=0;xint sign=2;//非法数字标志 int diannumber=0;//数中点的个数 string now[max]; string sn; int nowpointer=0;

|(x>0&&s[x]==46&&sign==1))//判断数字后跟字母还是字母后有数字

{

.

.

if(i==0) { } else {

if(sign==1) {

if(s[x]>=48&&s[x]<=57||s[x]==46) {

if(s[x]==46) { }

if(diannumber==0)

diannumber++;

if(s[x]>=48&&s[x]<=57) sign=1; else sign=2;

else sign=0;

}

}

else sign=0;

.

.

}

i++;

if(x==(s.length()-1)) {

sn=s.substr(x-i+1,i);

if(i>0) {

// cout<cout<if(sign==0)//数字后有字母的情况

cout<<\"

Error

(\"<{

// cout<<\" true\"<rowx++;

}

}

}

.

Error

.

}

else {

if(x>0&&(s[x-1]>&&s[x-1]<91)||(s[x-1]>96&&s[x-1]<123)||(s[x-1]>

=48&&s[x-1]<=57))//遇到分界符运算符 如果前面是数字或字母

{

sn=s.substr(x-i,i);

if(i>0)

{

// cout<cout<if(sign==0)

cout<<\" Error Error (\"<else

{

// cout<<\" true\"<}

rowx++;

}

.

.

i=0; }

string ll=s.substr(x,1);//判断是运算符还是分界符 wordlook(s[x],ll); if(fjf==0)//是运算符 {

i++;

if((s[x+1]>&&s[x+1]<91)||(s[x+1]>96&&s[x+1]<123)||(s[x+1]>=48&&

s[x+1]<=57))//如果后面是数字或字母

}

if(fjf==1)

{

sn=s.substr(x-i+1,i);

// cout<cout<wordlook(sn[0],sn); }

rowx++; i=0;

.

.

{

if((s[x-1]>&&s[x-1]<91)||(s[x-1]>96&&s[x-1]<123)||(s[x-1]>=48&&s[x-1]<=57))//如果前面是数字或字母 { }

else if(i>0) {

sn=s.substr(x-i,i);

// cout<outkey=1;

wordlook(sn[0],sn); rowx++; i=0;

}

cout<(2,\"<(\"<rowx++;

/* if(ll==\";\") {

rowy++;

.

符分

.

};

}

rowx=1; }

} */

}

int main() { /*

getline(cin,sn);// string带空格输入 cout<string instring;//读入一行 string sn;

.

.

*/

if(t>=48&&t<=57)

searcht(1,sn);

else { }

if((t>&&t<91)||(t>96&&t<123)) searcht(0,sn); else searcht(2,sn);

ifstream inputfile;//in file stream inputfile.open(salaryfile);

// inputfile>>noskipws;

if(!inputfile) { }

string pp;

while(!inputfile.eof())

cout<<\"no file\"<.

.

{

getline(inputfile,pp);

istringstream istr(pp);

string ppword; /*

{

pp.replace(begin, 1, \"\"); // 用空串替换str中从begin开始的1个字符

begin = pp.find(\" \查找空格在替换后的str中第一次出现的位置

int begin = 0;//去掉字符串的所有空格

begin = pp.find(\" \查找空格在str中第一次出现的位置 while(begin != -1) //表示字符串中存在空格

while(istr>>ppword)//按照空格分割字符串 { }

split(ppword);

.

.

}

// cout<<\"good \"<*/

// rowx++;

rowy++;//换行 }

七、实验总结

通过本次试验使我不仅对词法分析器有了更深的了解,而且提高了编程能力,希望在以后的学习中可以解决词法分析更多的问题。

}

return 0;

rowx=1;

实验2 LL(1)分析法

.

.

一、实验目的

通过完成预测分析法的语法分析程序,了解预测分析法和递归子程序法的区

别和联系。使学生了解语法分析的功能,掌握语法分析程序设计的原理和构造方

法,训练学生掌握开发应用程序的基本方法。有利于提高学生的专业素质,为培

养适应社会多方面需要的能力。 二、实验要求

1、编程时注意编程风格:空行的使用、注释的使用、缩进的使用等。 2、如果遇到错误的表达式,应输出错误提示信息。

3、对下列文法,用 LL(1)分析法对任意输入的符号串进行分析: (1)E->TG (2)G->+TG|—TG (3)G->ε (4)T->FS (5)S->*FS|/FS (6)S->ε (7)F->(E) (8)F->i 三、实验容

.

.

根据某一文法编制调试 LL ( 1 )分析程序,以便对任意输入的符号串 进行分析。

构造预测分析表,并利用分析表和一个栈来实现对上述程序设计语言的分 析程序。

分析法的功能是利用 LL(1)控制程序根据显示栈栈顶容、向前看符号 以及 LL(1)分析表,对输入符号串自上而下的分析过程。 四、实验步骤

1、根据流程图编写出各个模块的源程序代码上机调试。

2、 编制好源程序后,设计若干用例对系统进行全面的上机测试,并通过所设计 的 LL(1)分析程序;直至能够得到完全满意的结果。 3、书写实验报告 ;实验报告正文的容:

写出 LL(1)分析法的思想及写出符合 LL(1)分析法的文法。 程序结构描述:函数调用格式、参数含义、返回值描述、函数功能;函数 之间的调用关系图。

详细的算法描述(程序执行流程图) 。 给出软件的测试方法和测试结果。

实验总结 (设计的特点、不足、收获与体会)。

五、实验截图

.

.

六、核心代码

#include #include using namespace std; string pp;//输出字符串 string hh=\"\\r\\n\";//换行 const int max=50;

int endfu[max];//终止符序号表 int endfupointer=8;

char endfureal[max]={'+','-','*','/','(','i',')','#'}; int unendfu[max]; int unendfupointer=5;

char unendfureal[max]={'E','G','T','S','F'};

.

.

string

makemath[max]={\"E->TG\/FS\

//0 E->TG,1 G->+TG,2 G->-TG,3 G->$,4 T->FS,5 S->*FS,6 S->/FS,7 S->$,8 F->(E),9 F->i //$代表空串

string behavior[max]={\"初始化\int smarttable[max][max];//分析表

int checkendfu(char fu)//查终结符序号 {

int x;

for(x=0;xif(xif(endfureal[x]==fu) { }

break;

.

.

};

return x; else return -1;

int checkunendfu(char fu)//查非终结符序号 { };

string checkmakemath(int x)//查产生式表 { };

int checksmarttable(int x,int y)//查分析表 {

return smarttable[x][y]; return makemath[x]; int x;

for(x=0;xif(xif(unendfureal[x]==fu)

break;

.

.

};

class smartbox { public: smartbox() { box[0]='#'; box[1]='E'; boxpointer=1;

}

void push(char fu) { boxpointer++; box[boxpointer]=fu;

}

char pop() { char a=box[boxpointer]; if(a!='#')

{

//

cout<<\"pop: \"<.

// stringstream oss;

/* pp=pp+\"pop: \"; char buffer[max];

sprintf(buffer,\"%d\ string s=buffer; pp=pp+\" \"; pp=pp+s;

pp=pp+hh;

*/ boxpointer--; return a; }

} void check() { if(checkendfu(box[boxpointer])!=-1) {

char a;

// cout<//sprintf(buffer

.

.

//

pp=pp+box[boxpointer];

// pp=pp+checkendfu(box[boxpointer]);

// pp=pp+\" \";

a=pop();

// cout<<\"out \"<}

char box[max]; int boxpointer;

};

int main() { // TODO: Add extra validation here

// pp=pp+\"步骤 分析栈 剩余输入串 /*

string s1=\"sdsfs \\r\\nsdfsds\"; .

所用产生式动作\"+hh; .

string s3=\"aaaaaaaaaaaaa\"; s3=s3+s1;

CString s2(s3.c_str());

// CString s2=CString(s1);

SetDlgItemText(IDC_EDIT2,s2);//用SetDlgItemText(文本框ID,字符串),将文本框的容设置为字符串的容. SetDlgItemText(IDC_EDIT2,s2); */

// MessageBox(str);

string str; cin>>str;

int x,y;

for(x=0;xfor(y=0;ysmarttable[x][y]=99;

smarttable[0][4]=0;

smarttable[0][5]=0; smarttable[1][0]=1; smarttable[1][1]=2; smarttable[1][6]=3; smarttable[1][7]=3;

.

.

smarttable[2][4]=4; smarttable[2][5]=4; smarttable[3][0]=7; smarttable[3][1]=7; smarttable[3][2]=5; smarttable[3][3]=5; smarttable[3][6]=7; smarttable[3][7]=7; smarttable[4][4]=8; smarttable[4][5]=9;

smartbox mark; char fu; char enterfu; int endfunumber; int unendfunumber; string readyin; string enter;

// cin>>enter; //enter=\"i+i*i#\";

enter=str;

//enter=\"(i)#\";

.

.

int count=0;

//步骤

//分析栈

for(qq1=0;qq1<10-mark.boxpointer;qq1++)

//剩余输入栈

{ }

pp=pp+\" \";

for(int qq1=0;qq1<=mark.boxpointer;qq1++) { }

pp=pp+mark.box[qq1];

char buffer1[max];

sprintf(buffer1,\"%d\ string s1=buffer1;

pp=pp+s1+\" \";

.

.

string jiequ1=enter.substr(0,enter.length()); pp=pp+jiequ1;

for(int t1=0;t1<20;t1++) { }

pp=pp+\" \";

pp=pp+\" 初始化\"+hh;

//步骤

count++;

char buffer[max];

for(x=0;xsprintf(buffer,\"%d\ string s=buffer;

pp=pp+s+\" \";

.

.

//分析栈

for(qq=0;qq<10-mark.boxpointer;qq++)

for(int t=0;tpp=pp+\" \";

//剩余输入栈

string jiequ=enter.substr(x,enter.length()-x); pp=pp+jiequ;

{ }

pp=pp+\" \";

for(int qq=0;qq<=mark.boxpointer;qq++) { }

pp=pp+mark.box[qq];

.

.

enterfu=enter[x];

// cout<<\"enterfu: \"<mark.check(); fu=mark.pop();

cout<<\"fu: \"<cout<<\"sucessed!!!! over!!!!\"<//

//

}

unendfunumber=checkunendfu(fu); endfunumber=checkendfu(enterfu);

// cout<if(smarttable[unendfunumber][endfunumber]==99) {

pp=pp+\"error!!\"; break;

}

.

.

readyin=makemath[smarttable[unendfunumber][endfunumber]]; pp=pp+readyin;

for(int ddd=0;ddd<14-readyin.length();ddd++) { }

pp=pp+\" \";

pp=pp+\"POP,PUSH(\";

for(y=readyin.length()-1;y>2;y--) { }

pp=pp+\")\"+hh;

pp=pp+readyin[y];

// cout<<\"readyin: \"<int firsttime=0;

for(y=readyin.length()-1;y>2;y--) {

// cout<if(readyin[y]!='$') {

.

.

mark.push(readyin[y]); if(firsttime==0) {

if(checkendfu(readyin[y])!=-1)

{

// cout<<\"now x: \"<//步骤

count++;

char buffer[max];

sprintf(buffer,\"%d\ string s=buffer;

pp=pp+s+\" \";

//分析栈

for(qq=0;qq<10-mark.boxpointer;qq++)

{

for(int qq=0;qq<=mark.boxpointer;qq++) { }

pp=pp+mark.box[qq];

.

.

}

pp=pp+\" \";

//剩余输入栈

string jiequ=enter.substr(x,enter.length()-x); pp=pp+jiequ;

for(int t=0;tpp=pp+\" \";

pp=pp+\" GETNEXT(I)\"+hh; }

mark.check();

x++;

// cout<<\"next x: \"<firsttime=1;

}

// cout<pp=pp+hh;

//

.

.

}

cout<七、实验总结

通过本次试验使我不仅对ll(1)分析法有了更深的了解,而且提高了编程能力,希望在以后的学习中可以解决自动构造follow集的问题。

//CDialog::OnOK();

实验3 LR(1)分析法

一、实验目的

构造 LR(1)分析程序,利用它进行语法分析,判断给出的符号串是否为该文

法识别的句子,了解 LR(K)分析方法是严格的从左向右扫描,和自底向上的

语法分析方法。 二、实验要求

1、编程时注意编程风格:空行的使用、注释的使用、缩进的使用等。 2、如果遇到错误的表达式,应输出错误提示信息。 3、程序输入/输出实例:

输入一以#结束的符号串(包括+*()i#):在此位置输入符号串

.

.

输出过程如下:

步骤 状态栈 符号栈 剩余输入串 动 作 1 0 # i+i*i# 移进

i+i*i 的 LR分析过程

步骤 状态栈 符号栈 输入串 动作说明 1 0 # i+i*i# ACTION[0,i]=S5,状态5入栈 2 05 #i +i*i# r6: F→i 归约,GOTO(0,F)=3 入栈 3 03 #F +i*i# r4: T→F归约,GOTO(0,T)=3 入栈 4 02 #T +i*i# r2: E→T归约,GOTO(0,E)=1 入栈 5 01 #E +i*i# ACTION[1,+]=S6,状态6入栈 6 016 #E+ i*i# ACTION[6,i]=S5,状态5入栈 7 0165 #E+i *i# r6: F→i 归约,GOTO(6,F)=3 入栈 8 0163 #E+F *i# r4: T→F归约,GOTO(6,T)=9 入栈 9 0169 #E+T *i# ACTION[9,*]=S7,状态7入栈 10 01697 #E+T* i# ACTION[7,i]=S5,状态5入栈 11 016975 #E+T*i # r6:F→i 归约,GOTO(7,F)=10 入栈 12 0169710 #E+T*F # r3: T→T*F归约,GOTO(6,T)=9 入栈 13 0169 #E+T # r1:E→E+T,GOTO(0,E)=1 入栈 14 01 #E # Acc:分析成功 三、实验容

.

.

对下列文法,用 LR(1)分析法对任意输入的符号串进行分析: (1)E-> E+T (2)E->T (3)T-> T*F (4)T->F (5)F-> (E) (6)F-> i 四、实验步骤

1、根据流程图编写出各个模块的源程序代码上机调试。

2、编制好源程序后,设计若干用例对系统进行全面的上机测试,并通过所设计 的 LR(1)语法分析程序;直至能够得到完全满意的结果。 3、书写实验报告 ;实验报告正文的容: 描述 LR(1)语法分析程序的设计思想。

程序结构描述:函数调用格式、参数含义、返回值描述、函数功能;函数 之间的调用关系图。

详细的算法描述(程序执行流程图) 。 给出软件的测试方法和测试结果。 五、实验截图

.

.

六、核心代码

#include #include using namespace std; int count=1;

string pp;//输出字符串 string hh=\"\\r\\n\";//换行 const int max=100;

char endfureal[max]={'i','+','*','(',')','#','E','T','F'}; int endfupointer=8;

.

.

string

creatword[max]={\"E->E+T\//(0)E-> E+T(1)E->T (2)T-> T*F (3)T->F (4)F-> (E) (5)F-> i //注意rj时j应对应数组下标

int checkendfu(char fu)//查终结符序号 { };

class actiongo//原子动作 {

public:actiongo()

{ int x;

for(x=0;x<=endfupointer;x++) { }

if(x<=endfupointer) return x; else return -1;

if(endfureal[x]==fu) { }

break;

.

.

};

// cout<<\"eroor! wrong action or goto creat\"<}

action(int i,int j) {

actype=i; number=j;

// cout<int actype;//0=s 1=r 2=acc 3=goto表 4=wrong int number;

actiongo smarttable[max][max]; class stylebox//状态栈 { public:

stylebox() { }

box[0]=0; boxpointer=0;

.

.

void push(int style) { }

int pop() {

int a=box[boxpointer]; boxpointer--;

cout<<\"pop now\"<box[boxpointer]=style;

// };

}

int box[max]; int boxpointer;

class readybox//已归约栈 { public:

readybox() {

.

.

box[0]='#'; boxpointer=0;

}

void push(char fu) { boxpointer++; box[boxpointer]=fu;

}

char pop() { char a=box[boxpointer]; boxpointer--; return a; }

char box[max]; int boxpointer;

};

int program(stylebox&style,readybox&ready,char ptr,int control)//返回是否需要移进信号 {

.

fu,int icount,string .

if(control==1) {

//---------------------------------------------------------

//////////////////////////////

char ber[max];

sprintf(ber,\"%d\ string st=ber;

pp=pp+st+\" \";

count++;

////////////////////////////////////

pp=pp+\" \";

for(int qq=0;qq<=style.boxpointer;qq++)

char bss[max];

{

.

.

sprintf(bss,\"%d\ string st=bss;

pp=pp+st;

}

for(qq=0;qq<10-style.boxpointer;qq++)

{ }

pp=pp+\" \";

for( qq=0;qq<=ready.boxpointer;qq++)

{

pp=pp+ready.box[qq];

}

for(qq=0;qq<10-ready.boxpointer;qq++) { }

pp=pp+\" \";

.

.

//--------------------------------------------------------- }

////////////////////////////////////////

for(int dj=icount;djpp=pp+\" \";

pp=pp+ptr[dj];

.

.

int i=style.pop();//如果是s则状态还要入栈

// cout<<\"现在状态\"<}

int j=checkendfu(fu); if(j==-1) {

pp=pp+\"error!!!\"; return 4;//wrong!!!

// cout<<\" 现在符号: \"<int checkstyle=smarttable[i][j].actype;//查表

.

.

if(checkstyle==4) { pp=pp+\"error!!!\";

return 4;//wrong!!!

} if(checkstyle==0||checkstyle==3)

{

style.push(i);//如果是s则状态还要入栈

if(checkstyle==0)

{

//cout<<\"ACTION[\"<.

状.

pp=pp+\"ACTION[\";

char buffer[max];

}

sprintf(buffer,\"%d\ string s=buffer; pp=pp+s; pp=pp+\pp=pp+fu; pp=pp+\"]=S\"; char buf[max];

sprintf(buf,\"%d\ s=buf; pp=pp+s; pp=pp+\状态\"; pp=pp+s+\"入栈\"+hh;

.

.

if(checkstyle==3) { //

cout<\"<}

ready.push(fu);

style.push(smarttable[i][j].number); cout<char bf[max];

sprintf(bf,\"%d\ string s=bf; pp=pp+s;

pp=pp+\ char bfff[max];

sprintf(bfff,\"%d\ s=bfff;

pp=pp+s+\"入栈\"+hh;

//

.

.

}

if(checkstyle==1) {

string l=creatword[smarttable[i][j].number];

// cout<<\"r\"<pp=pp+\"r\";

int dd=smarttable[i][j].number+1;

char bfc[max];

sprintf(bfc,\"%d\ string ss=bfc;

pp=pp+ss+\": \"+l+\"归约,GOTO(\";

char n;//pop用的 int x;

// cout<char sq=ready.pop();

for(x=0;x.

.

}

n=style.pop(); n=ready.pop(); cout<//

// cout<x=program(style,ready,l[0],icount,ptr,0);//识别非终结符

return 0;//归约 }

if(checkstyle==2)

{ }

int main() {

//0=i 1=+ 2=* 3=( 4=) 5=# 6=E 7=T 8=F

// TODO: Add extra validation here string str; cin>>str; }

return 2;//接受

.

.

smarttable[0][0].action(0,5); smarttable[0][3].action(0,4); smarttable[0][6].action(3,1); smarttable[0][7].action(3,2); smarttable[0][8].action(3,3); smarttable[1][1].action(0,6); smarttable[1][5].action(2,0); smarttable[2][1].action(1,1); smarttable[2][2].action(0,7); smarttable[2][4].action(1,1); smarttable[2][5].action(1,1); smarttable[3][1].action(1,3); smarttable[3][2].action(1,3); smarttable[3][4].action(1,3); smarttable[3][5].action(1,3); smarttable[4][0].action(0,5); smarttable[4][3].action(0,4); smarttable[4][6].action(3,8); smarttable[4][7].action(3,2); smarttable[4][8].action(3,3); smarttable[5][1].action(1,5); smarttable[5][2].action(1,5);

.

.

smarttable[5][4].action(1,5); smarttable[5][5].action(1,5); smarttable[6][0].action(0,5); smarttable[6][3].action(0,4); smarttable[6][7].action(3,9); smarttable[6][8].action(3,3); smarttable[7][0].action(0,5); smarttable[7][3].action(0,4); smarttable[7][8].action(3,10); smarttable[8][1].action(0,6); smarttable[8][4].action(0,11); smarttable[9][1].action(1,0); smarttable[9][2].action(0,7); smarttable[9][4].action(1,0); smarttable[9][5].action(1,0); smarttable[10][1].action(1,2); smarttable[10][2].action(1,2); smarttable[10][4].action(1,2); smarttable[10][5].action(1,2); smarttable[11][1].action(1,4); smarttable[11][2].action(1,4); smarttable[11][4].action(1,4);

.

.

smarttable[11][5].action(1,4);

string enter=str;

int i; int x; stylebox st; readybox ready;

for(i=0;i// cout<<\"----------------enter:

----------------\"<// cout<<\"Acc:分析成功\"<pp=pp+\"Acc:分析成功\"+hh;

break;

.

\"<.

} if(x==4)

break;

// cout<cout<// CDialog::OnOK(); }

七、实验总结

通过本次试验使我不仅对LR(1)分析法有了更深的了解,而且提高了编程能力,希望在以后的学习中可以解决LR(1)中确定化的问题。

.

.

.

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- efsc.cn 版权所有 赣ICP备2024042792号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务