#include
#include
#include
#include
#include
#include
#include
#include
#define NULL 0
struct Stack // 栈结构体: 序号、内容、连接下一结点指针
{
int num;
char name;
struct Stack *next;
};
struct Guiyue// 规则集结构体:序号、规则长度、符号、连接下一结点指针
{
int num;
int count;
char name;
struct Guiyue *next;
};
struct Relation // 分析表结构体:状态序号、对应符号列、操作类型的对应序号、操作类型、连接下一结点指针
{
int line_States ;
char rank_Letter;
int relationship;
char name;
struct Relation *next;
};
struct Sign // 符号表结构体: 自变量名、标识类型、连接下一结点指针
{
char name[20];
char kind;
struct Sign *next;
};
struct Word // 单词表结构体: 单词名字、标识类型、状态、序号、行号、连接符号表指针、连接下一结点指针
{
char name[20];
char mark_name;
int state;
int num;
int line;
struct Sign *link;
struct Word *next;
};
FILE *fp1;//文件指针
int row=1,line[10000],Lin[300],w_num;//字符行变量、字符行、单词所在行、字符数
char buffer[10000];//字符串缓冲区
Stack *MarkPush(Stack *ip,char mark,int I_i)//压栈
{
Stack *s;
s=(Stack *)malloc(sizeof(Stack));
s->name=mark;
s->num=I_i;
s->next=ip;
ip=s;
return ip;
}
void MarkPop(Stack *ip)//出栈
{
Stack *q;
char name;
name=ip->name;
q=ip->next;
if(ip->next!=NULL)
{
ip->name=ip->next->name;
ip->num=ip->next->num;
ip->next=ip->next->next;
free(q);
}
}
int judge(char ch)// 接收ch判断字符,变量flag返回字符类别
{
int flag;
if(ch=='!'||ch=='$'||ch=='&'||ch=='*'||ch=='('||ch==')'||ch=='-'||ch=='_'||
ch=='+'||ch=='='||ch=='|'||ch=='{'||ch=='}'||ch=='['||ch==']'||ch==';'||
ch==':'||ch=='"'||ch=='<'||ch==','||ch=='>'||ch=='.'||ch=='/'||ch=='\'')
flag=1;
else if('0'<=ch&&ch<='9')
flag=2;
else if(('a'<=ch&&ch<='z')||('A'<=ch&&ch<='Z'))
flag=3;
else if(ch==' ')
flag=4;
else if(ch=='\n')
flag=5;
else if(ch=='?')
flag=6;
else if(feof(fp1))
flag=7;//结束
else
flag=0; //illegal character
return(flag);
}
//======================================================================================================
// 词法分析函数: void scan()
// 数据传递: 形参fp接收指向文本文件头的文件指针;
// 全局变量buffer与line对应保存源文件字符及其行号,char_num保存字符总数。
void scan()
{
char ch;
int flag,j=0,i=-1;
while(!feof(fp1))
{
ch=fgetc(fp1);
flag=judge(ch);
printf("%c",ch);//显示打开的文件
if(flag==1||flag==2||flag==3) {i++;buffer[i]=ch;line[i]=row;}
else if(flag==4) {i++;buffer[i]='?';line[i]=row;}
else if(flag==5) {i++;buffer[i]='~';row++;}
else if(flag==7) continue;
else cout<<"\n请注意,第"<kind='\0';
s_first->name[0]='\0';
news=head=ft=(struct Word *)malloc(sizeof(struct Word));
ft->link=s_first;
ft->next=NULL;
//====================================分割单词功能==========================================================
int i=0,k,flag,jud=0;
for(k=0;kname[i]=buffer[k];
news->name[++i]='\0';
}
else {//2~
i=0;
ft=news;
if(news->name[0]>=33&&news->name[0]<=125){
news=(struct Word *)malloc(sizeof(struct Word));
ft->next=news;
news->next=NULL;
}
if(flag==1){//3~
if(buffer[k]=='/'&&buffer[k+1]=='/') jud=1;
else if(buffer[k]=='/'&&buffer[k+1]=='*') jud=2;
else{//4~
news->name[i]=buffer[k];
if((buffer[k]=='='&&buffer[k+1]=='=')||(buffer[k]=='&'&&buffer[k+1]=='&')||
(buffer[k]=='|'&&buffer[k+1]=='|')||(buffer[k]=='>'&&buffer[k+1]=='=')||
(buffer[k]=='<'&&buffer[k+1]=='=')||(buffer[k]=='!'&&buffer[k+1]=='=')){
k=k+1;
i=i+1;
printf("%d",i);
news->name[i]=buffer[k];
}
news->name[1+i]='\0';
ft=news;
news=(struct Word *)malloc(sizeof(struct Word));
ft->next=news;
news->next=NULL;
}//4~
}//3~
}//2~
}//1~
else if(jud==1)
if(buffer[k]=='~') jud=0;
else ;
else if(jud==2)
if(buffer[k]=='*'&&buffer[k+1]=='/') { jud=0; k=k+1;}
else ;
}
if(news->name[0]<33||news->name[0]>125) ft->next=NULL;
/*******************单词转换成标识符*******************/
ft=head;
while(ft){
if(strcmp(ft->name,"main")==0){ft->mark_name='m';}
else if(strcmp(ft->name,"void")==0){ft->mark_name='v';}
else if(strcmp(ft->name,"while")==0){ft->mark_name='w';}
else if(strcmp(ft->name,"if")==0){ft->mark_name='f';}
else if(strcmp(ft->name,"else")==0){ft->mark_name='e';}
else if(strcmp(ft->name,"int")==0){ft->mark_name='a';}
else if(strcmp(ft->name,"float")==0){ft->mark_name='b';}
else if(strcmp(ft->name,"double")==0){ft->mark_name='d';}
else if(strcmp(ft->name,"char")==0){ft->mark_name='c';}
else if(ft->name[0]>='0'&&ft->name[0]<='9'){ft->mark_name='n';}
else if(ft->name[0]=='+'||ft->name[0]=='-'||ft->name[0]=='*'||ft->name[0]=='/'
||ft->name[0]=='='||ft->name[0]=='<'||ft->name[0]=='>'
||ft->name[0]==','||ft->name[0]==';'||ft->name[0]=='('||ft->name[0]==')'
||ft->name[0]=='{'||ft->name[0]=='}'){ft->mark_name=ft->name[0];}
else if(strcmp(ft->name,"&&")==0){ft->mark_name='&';}
else if(strcmp(ft->name,"||")==0){ft->mark_name='|';}
else if(strcmp(ft->name,"!=")==0){ft->mark_name='@';}
else if(strcmp(ft->name,"==")==0){ft->mark_name='#';}
else {ft->mark_name='i';}
ft=ft->next;
}
/********************初始化单词表的序号和行号********************/
i=0;
ft=head;
while(ft){
ft->num=i;
ft->line=Lin[i];
i++;
ft=ft->next;
}
/*************************初始化符号表*************************/
ft=head;
char word_type;
while(ft){//1~
if(ft->mark_name=='a'||ft->mark_name=='b'||ft->mark_name=='c'||ft->mark_name=='d'){//2~
p=ft->next;
word_type=ft->mark_name;
while(p->mark_name!=';'){
if(p->mark_name!=','){
s_look=(struct Sign *)malloc(sizeof(struct Sign));
s_look->kind=word_type;
strcpy(s_look->name,p->name);
s_first->next=s_look;
s_first=s_look;
s_look->next=NULL;
}
p=p->next;
}
ft=p;
}//2~
ft=ft->next;
}//1~
return(head);
}
//=====================================================================================================
//正确性检测函数: FindWordDeclare(Word *head)
// 数据传递: *head:单词表的头指针.
// 备注: 查找保留字是否被声名和符号是否对称.
void FindWordDeclare(Word *head){
struct Sign *s_first;
struct Word *find,*w_name[1000],*word_fu[100];
struct Stack *ip,*q;
int i,cal=0,ca=0,end;
find=head;
cout<mark_name=='i'){
w_name[cal]=find;
cal++;
}
if(find->next!=NULL){
if((find->mark_name==find->next->mark_name)&&(find->mark_name!='{')&&
(find->mark_name!='}')&&(find->mark_name!='(')&&(find->mark_name!=')'))
cout<<"第 "<line<<" 行,‘ "<mark_name<<" ’存在字符重复错误 !"<mark_name=='i'&&find->next->mark_name=='}')||(find->mark_name==','&&find->next->mark_name=='}')||
(find->mark_name==','&&find->next->mark_name==';')||(find->mark_name==';'&&find->next->mark_name==',')||
(find->mark_name=='('&&find->next->mark_name==',')||(find->mark_name==','&&find->next->mark_name=='(')||
(find->mark_name==')'&&find->next->mark_name==';')||(find->mark_name==')'&&find->next->mark_name==',')||
(find->mark_name==')'&&find->next->mark_name=='}')){
cout<<"第 "<line<<" 行,"<name<<" 处存在符号连接错误 !"<mark_name=='a'||find->mark_name=='b'||find->mark_name=='c'||find->mark_name=='d')&&
(find->next->mark_name=='}'||find->next->mark_name=='{'||find->next->mark_name==','||
find->next->mark_name==';'||find->next->mark_name=='('||find->next->mark_name==')'||
find->next->mark_name=='+'||find->next->mark_name=='-'||find->next->mark_name=='*'||
find->next->mark_name=='/'||find->next->mark_name=='&'||find->next->mark_name=='>'||
find->next->mark_name=='<'||find->next->mark_name=='='||find->next->mark_name=='!'||
find->next->mark_name=='@'||find->next->mark_name=='n'))
cout<<"第 "<line<<" 行,‘ "<mark_name<<" ’存在自变量声明搭配错误 !"<mark_name=='('||find->mark_name==')'||find->mark_name=='{'||find->mark_name=='}'){
word_fu[ca]=find;
ca++;
}
if(find->name[0]>='0'&&find->name[0]<='9'&&find->name[1]>='a'&&find->name[1]<='z')
cout<<"第 "<line<<" 行, "<name<<" 存在变量声明错误 !"<next;
}
int j=0;
for(i=0;ilink;
end=1;
while(s_first&&end){
if(strcmp(s_first->name,w_name[i]->name)==0) end=0;
else s_first=s_first->next;
}
if(end==1&&i!=cal-1) cout<<"错误 ! 第 "<line<<" 行,变量 "<name<<" 没有被声明 !"<name='$';
for(i=0;imark_name=='(')||(word_fu[i]->mark_name=='{')) ip=MarkPush(ip,word_fu[i]->mark_name,i);
else if((ip->name=='('&&word_fu[i]->mark_name==')')||(ip->name=='{'&&word_fu[i]->mark_name=='}')) MarkPop(ip);
else cout<<"错误 ! 第 "<line<<" 行,“ "<name<<" ” 存在符号匹配错误 ! "<name!='$') cout<<"错误 ! 第 "<line<<" 行,“ "<name<<" ” 存在符号匹配错误 !"<','@','#',
')'},{'i'},{'&',')'},{'+',';'},{'+','-',';',')'},{'+','-','/',';',')'},{'+','-',
'*','/',';',')'},{'+','-','*','/',';',')'},{'i','(','n','L','I','K','T','F'},
{'+','-','*','/',';',')'},{'+','-','*','/',';',')'},{'i'},{',',';'},{'{'},{'i',
'!','(','H','G'},{'i','!','(','G'},{'&',')'},{'&','|',')'},{'i'},{'i'},{'i'},
{'i'},{'&','|',')'},{'&','|',')'},{'&','|',')'},{'&','|',')'},{'{'},{'i','(',
'n','I','K','T','F'},{'i','(','n','K','T','F'},{'i','(','n','T','F'},{'i','(',
'n','F'},{'+',')'},{'i','a','b','c','d','f','w','A','C','X','Y','S'},{'&','|',
')'},{'&','|',')'},{'i','a','b','c','d','f','w','A','C','X','Y','S'},{'+','-',
';',')'},{'+','-','/',';',')'},{'+','-','*','/',';',')'},{'+','-','*','/',';',
')'},{'+','-','*','/',';',')'},{'}'},{'}'},{'i','}','a','b','c','d','f','w'},
{'e'},{'{'},{'i','a','b','c','d','f','w','A','C','X','Y','S'},{'}'},{'i','}',
'a','b','c','d','f','w'},{'&','|',')'},{'i','}','a','b','c','d','f','w','}'}};
//初始化关系表
for(int i=0;i<84;i++){
for(int j=0;jline_States=i;
r_new->rank_Letter=Let[i][j];
r_new->relationship=sr[i][j];
r_new->name=SS[i][j];
r_find->next=r_new;
r_find=r_new;
r_new->next=NULL;
}
}
return r_head;
}
//======================================================================================================
//初始化规则表函数: Guiyue *guiyue()
// 数据传递: g_head返回规则表的头指针
Guiyue *FirstGuiyue(){
Guiyue *g_head,*g_find,*g_new;
g_head=NULL;
//规约
char root[]={'B','Q','S','A','A','C','C','X','Y','Y','Y','Y','Z','Z','S','S','S','E','E','H',
'H','G','G','G','G','G','G','G','L','L','I','I','K','K','T','T','F','F','F'};
int LR[]={1,7,3,2,1,3,1,2,1,1,1,1,3,1,11,7,4,3,1,3,1,3,3,3,3,3,2,1,3,1,3,1,3,1,3,1,3,1,1};
//初始化规则表
for(int i=0;i<39;i++){
g_new=(Guiyue *)malloc(sizeof(Guiyue));
if(g_head==NULL){
g_find=g_head=g_new;
}
g_new->num=i;
g_new->count=LR[i];
g_new->name=root[i];
g_find->next=g_new;
g_find=g_new;
g_new->next=NULL;
}
return g_head;
}
//======================================================================================================
//语法分析函数: int ResultAnely(Relation *r_head,Stack *s_head,char str[],Guiyue *g_head,int cal)
// 数据传递: 1 *r_head:分析表头指针.
// 2 *s_head:符号栈头指针.
// 3 str[] :转义字符流.
// 4 *g_head:规则表头指针.
// 5 cal :转义字符流的长度.
int ResultAnely(Relation *r_head,Stack *s_head,char str[],Guiyue *g_head,int cal){
Relation *r_find;
Guiyue *g_find;
Stack *s_find,*s_look;
s_find=s_head;
int j,v,admition=1,goon=1,in,out=1,hang=-1,count;
char stack[200],name;
// cout<<"\n===================显--示--语--法--分--析--过--程--及--结--果==================="<line_States==s_find->num&&r_find->rank_Letter==str[0]&&r_find->name=='s'){//:入栈
s_find=MarkPush(s_find,str[0],r_find->relationship);
admit=0;
for(in=0;innext;
}//:入栈~
if(r_find->line_States==s_find->num&&r_find->rank_Letter==str[0]&&r_find->name=='r'){//:规约
g_find=g_head;
int g=r_find->relationship;
while(g) {g_find=g_find->next;g--; }
name=g_find->name;
count=g_find->count;
admit=0;
for(int k=0;kline_States==s_find->num && r_find->rank_Letter==name){
s_find=MarkPush(s_find,name,r_find->relationship);
a=0;
}
r_find=r_find->next;
}
}//:规约~
if(r_find->line_States==s_find->num&&r_find->rank_Letter==str[0]&&r_find->name=='o'){//:2判断运算结束
admit=0;
goon=0;
out=0;
cout<<"\nSuccession !"<next;
}//:2~
/* if(out==1)//显示语法分析结果
{
s_look=s_find;
v=0;
while(s_look)
{
stack[v]=s_look->name;
s_look=s_look->next;
v++;
}
cout<=0;j--)
{
cout<name='$';
stack_a->next=NULL;
stack_b=(struct Stack *)malloc(sizeof(struct Stack));
stack_b->name='#';
stack_b->next=NULL;
f_head=NULL;
int admit,cal,four;
four=1;// 四元式序号
cal=0;
admit=1;
while(admit){
if(str[cal]=='='){
stack_a=MarkPush(stack_a,str[cal],cal);
cal++;
}
else if(stack_b->name=='#'||stack_b->name=='+'||stack_b->name=='-'||stack_b->name=='*'||stack_b->name=='/')
{
if((str[cal]>='a')&&(str[cal]<='z')||(str[cal]>='0')&&(str[cal]<='9')){
stack_a=MarkPush(stack_a,str[cal],cal);
cal++;
}
else if(str[cal]=='('){
stack_b=MarkPush(stack_b,'#',cal);
cal++;
}
else if((stack_b->name=='#')&&(str[cal]=='+'||str[cal]=='-'||str[cal]=='*'||str[cal]=='/')){
stack_b=MarkPush(stack_b,str[cal],cal);
cal++;
}
else if((stack_b->name=='#')&&(str[cal]==')')){
MarkPop(stack_b);
cal++;
}
else if((stack_b->name=='#')&&(str[cal]==';')){
admit=0;
}
else if(stack_b->name=='+'||stack_b->name=='-'||stack_b->name=='*'||stack_b->name=='/'){
if((stack_b->name=='+'||stack_b->name=='-')&&(str[cal]=='*'||str[cal]=='/')){
stack_b=MarkPush(stack_b,str[cal],cal);
cal++;
}
else{
if(f_head==NULL){
f_new=(struct FourStyle *)malloc(sizeof(struct FourStyle));
f_find=f_new;
f_head=f_find;
}
else{
f_new=(struct FourStyle *)malloc(sizeof(struct FourStyle));
f_find->next=f_new;
f_find=f_new;
f_new->next=NULL;
}
f_new->num=order_num;
f_new->Word=stack_b->name;
MarkPop(stack_b);
f_new->Opr2=stack_a->name;
MarkPop(stack_a);
f_new->Opr1=stack_a->name;
MarkPop(stack_a);
temp=four+65;
f_new->Result=temp;
stack_a=MarkPush(stack_a,f_new->Result,cal);
four++;
}
}
}
if(cal!=3&&admit==0&&str[cal]==';'){
f_new=(struct FourStyle *)malloc(sizeof(struct FourStyle));
f_new->num=order_num;
f_new->Opr1=stack_a->name;
MarkPop(stack_a);
f_new->Word=stack_a->name;
MarkPop(stack_a);
f_new->Opr2='_';
f_new->Result=stack_a->name;
MarkPop(stack_a);
f_find->next=f_new;
f_find=f_new;
f_new->next=NULL;
four++;
}
else if(cal==3&&admit==0&&str[cal]==';'){
f_new=(struct FourStyle *)malloc(sizeof(struct FourStyle));
f_new->num=order_num;
f_new->Opr1=stack_a->name;
MarkPop(stack_a);
f_new->Word=stack_a->name;
MarkPop(stack_a);
f_new->Opr2='_';
f_new->Result=stack_a->name;
f_head=f_new;
f_new->next=NULL;
four++;
}
}
f_find=f_head;
while(f_find){
/*cout.width(20);*/cout<num<<" "<Word<<" "<Opr1<<" "<Opr2<<" "<Result<next;
}
}
//======================================================================================================
// 布尔表达式四元式函数: void BoolStyle(char str[],int order_num)
// 数据传递:1.str[] :转义字符流.
// 2 order_num :表达式所在行.
void BoolStyle(char str[],int order_num){
struct FourStyle{
char Word,Opr1,Opr2;
int Order,num;
struct FourStyle *next;
};
struct FourStyle *b_head,*b_find,*b_new,*p[100];
b_head=NULL;
int cal,admit,i=0;
admit=1;
cal=0;
while(admit){
if(str[cal]!='|'&&str[cal]!='&'){
if(b_head==NULL){
b_find=b_new=(struct FourStyle *)malloc(sizeof(struct FourStyle));
b_head=b_find;
p[i]=b_find;
i++;
}
else{
b_new=(struct FourStyle *)malloc(sizeof(struct FourStyle));
p[i]=b_new;i++;
b_find->next=b_new;
b_find=b_new;
b_new->next=NULL;
}
b_new->Opr1=str[cal];cal++;
b_new->Word=str[cal];cal++;
b_new->Opr2=str[cal];cal++;
b_new->num=order_num;
b_new->Order=0;
b_new=(struct FourStyle *)malloc(sizeof(struct FourStyle));
p[i]=b_new;i++;
b_new->Opr1='_';
b_new->Word='j';
b_new->Opr2='_';
b_new->num=order_num;
b_new->Order=0;
b_find->next=b_new;
b_find=b_new;
b_new->next=NULL;
}
else if(str[cal]=='|'){
p[i-1]->Order=p[i-1]->num+1;
cal++;
}
else if(str[cal]=='&'){
p[i-2]->Order=p[i-2]->num+2;
cal++;
}
if(str[cal]=='$'){
admit=0;
p[0]->Order=order_num;
p[i-2]->Order=p[i-2]->num+2;
if(str[cal-4]=='&'){
p[i-1]->Order=p[i-3]->num;
}
}
}
b_find=b_head;
while(b_find){
cout<num<<" "<Word<<" "<Opr1<<" "<Opr2<<" "<Order<next;
}
}
//======================================================================================================
// 显示四元式函数: FourStyle(int goon,Word *head)
// 数据传递:1.goon :语法分析成功标志
// 2 head :单词表头指针.
void FourStyle(int goon,Word *head){
Word *find;
find=head;
int jishu=0,order_num=1;
char str1[20];
cout<next->mark_name=='='){
order_num=find->line;
jishu=0;
while(find->mark_name!=';'){
str1[jishu]=find->name[0];
jishu++;
find=find->next;
}
str1[jishu]=';';
str1[jishu+1]='\0';
ProduceStyle(str1,order_num);
}
else if(find->mark_name=='f'||find->mark_name=='w'){
jishu=0;
find=find->next->next;
order_num=find->line;
while(find->next->mark_name!='{'){
str1[jishu]=find->name[0];
jishu++;
find=find->next;
}
str1[jishu]='$';
str1[jishu+1]='\0';
BoolStyle(str1,order_num);
}
else if(find->mark_name=='e'){
find=find->next->next;
order_num=find->line;
if(find->next->mark_name=='='){
jishu=0;
while(find->mark_name!=';'){
str1[jishu]=find->name[0];
jishu++;
find=find->next;
}
str1[jishu]=';';
str1[jishu+1]='\0';
ProduceStyle(str1,order_num);
}
else if(find->mark_name=='f'||find->mark_name=='w'){
order_num=find->line;
jishu=0;
find=find->next->next;
while(find->next->mark_name!='{'){
str1[jishu]=find->name[0];
jishu++;
find=find->next;
}
str1[jishu]='$';
str1[jishu+1]='\0';
BoolStyle(str1,order_num);
}
}
find=find->next;
if(find->next==NULL){goon=0;}
}
cout<mark_name<mark_name;i++;}
w_look=w_look->next;
}
break;
}
case 2:
{
cout<num<<"\t\t"<line<<"\t\t"<name<<"\t\t"<mark_name<next;
}
cout<<"WordNumber WordLine WordName WordMark"<link;
cout<<"DataType"<<" "<<"SignName";
while(s_look){
cout<<" "<kind<<"\t\t"<name<next;
}
break;
}
case 4:
{
cout<line_States){
cout<<" "<rank_Letter<<"="<name<relationship;
}
else{
l++;
cout<rank_Letter<<"="<name<relationship;
}
r_new=r_new->next;
}
break;
}
}
}
//======================================================================================================
// 主函数: void main()
void main(){
struct Word *head,*find;
struct Relation *r_head;
struct Guiyue *g_head;
struct Stack *s_head;
head=(Word *)malloc(sizeof(Word));
head->next=NULL;
r_head=(Relation *)malloc(sizeof(Relation));
r_head->next=NULL;
s_head=(Stack *)malloc(sizeof(Stack));
s_head->name='$';
s_head->num=0;
s_head->next=NULL;
int goon=2,cal,i=0;
char document[50],str[1000];//另存输入流
FILE *fp2;
cout<<"请输入源代码文件名,如: li.txt liyoubu.txt \n文件名: ";
cin>>document;
cout<next==NULL){
scan(); //生成输入流(1),从文件中扫描源代码语句,保存在缓冲区
head=InitWord(); //生成单词表(2),从缓冲区中读取字符串语句,进行词法分析
find=head;
while(find){
str[i]=find->mark_name;
find=find->next;
i++;
}
str[i]='$';
str[i+1]='\0';
cal=i+1;
}
//system("pause");
// Print(flag,head,fp2,r_head);
flag++;
system("pause");
Print(flag,head,fp2,r_head);
flag++;
system("pause");
if(r_head->next==NULL){
g_head=FirstGuiyue();//从文件中读取文法语句,打印文法
r_head=FirstRelation();//生成LR分析表
}
//if (flag==3) { Print(flag,head,fp2,r_head); continue; }
if(goon==2){
goon=ResultAnely(r_head,s_head,str,g_head,cal);//语法分析
FindWordDeclare(head);//检查正确性,判断符号是否对称
}
// if (flag==3) continue;
system("pause");
flag++;
FourStyle(goon,head);//生成四元式(4)
flag=0;
// }
fclose(fp1);
fclose(fp2);
}
li.txt
void main ()
{
int a,b,x,y,max;
a=9;
b=8;
while(a>b)
{
b=a+a;
a=a-1;
}
x=a+b;
y=b+b;
if(x>y) { max=x;}
else {max=y; }
}
liyoubu.txt
void main ()
{
int a,b,x,2x,y,max;
a=9;
b=8;
b1=8;
while(a>b)
{
b=a*a;
a=a-1;
}
x=a+b;
y=b+b;
if(x>y) { max=x}
else {max=y; }
}
}
LR.txt
[Terminator] m v ( ) { } i = ; f e w a b c d , & | < > # @ + - * / n
[NonTerminator] B Q S A C X Y Z E H G L I K T F
[Starter] B
[Precept]
00、B->Q
01、Q->v m ( ) { A }
02、S->C ; S
03、A->S A
04、A->S
05、C->C ; X
06、C->X
07、X->Y Z
08、Y->a
09、Y->b
10、Y->c
11、Y->d
12、Z->i , i
13、Z->i
14、S->f ( E ) { A } e { A }
15、S->w ( E ) { A }
16、S->i = L ;
17、E->E & H
18、E->H
19、H->H | G
20、H->G
21、G->i < i
22、G->i > i
23、G->i # i
24、G->i @ i
25、G->( E )
26、G->! E
27、G->i
28、L->L + I
29、L->I
30、I->I - K
31、I->K
32、K->K / T
33、K->K
34、T->T * F
35、T->F
36、F->( L )
37、F->n
38、F->i
本文档为【简单C语言编译器(编译原理)】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。