C++改控制台手动输入为文件TXT输入 5
#include"stdafx.h"int_tmain(intargc,_TCHAR*argv[]){return0;}#include"stdafx.h"#includ...
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
#include "stdafx.h"
#include<stdio.h>
#include<string.h>
#include "wordscan.h"
void parser();
void yucu();
void statement();
void expression();
void term();
void factor();
int kk=0;
void parser()
{
if (c==1) //begin
{
scanner();
yucu();
if (c==2) //end
{
scanner();
if (c==0 && kk==0)
printf("THIS STATEMENT IS RIGHT! \n");
}
else
{
if(kk!=1)
printf("Error,losing 'end' ! \n");
kk=1;
}
}else
{
printf("Error,losing 'begin' ! \n");
kk=1;
}
return;
}
void yucu()
{
statement();
while(c==26) //语句分割“;”
{
scanner();
statement();
}
return;
}
void statement()
{
if (c==6) //为标识符
{
scanner();
if (c==14) //为a :=
{
scanner();
expression();
}else if (c==2){
/*printf("THIS STATEMENT IS RIGHT\n");*/
}else if (c==26){
/*printf("THIS STATEMENT IS RIGHT\n");*/
}else
{
printf("Statement error:1!\n");
kk=1;
}
}
else
{
printf("Statement error:2!\n");
kk=1;
}
return;
}
void expression()
{
term();
while(c==15 || c==16)
{
scanner();
term();
}
return;
}
void term()
{
factor();
while(c==17 || c==18)
{
scanner();
factor();
}
return;
}
void factor()
{
if(c==6 || c==7) scanner(); //为标识符或整常数时读下一个单词符号
else if(c==27)
{
scanner();
expression();
if(c==28) scanner();
else {printf(" ')' 错误\n"); kk=1;}
}
else { printf("表达式错误\n"); kk=1;}
return;
}
void main()
{
p=0;
printf("********************语法分析程序***************\n");
printf("请输入源程序\n");
do
{
scanf("%c",&ch);
prog[p++]=ch;
}while(ch!='\n');
p=0;
scanner();
parser();
printf("语法分析结束! \n");
getchar();getchar();getchar();getchar();
} 展开
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
#include "stdafx.h"
#include<stdio.h>
#include<string.h>
#include "wordscan.h"
void parser();
void yucu();
void statement();
void expression();
void term();
void factor();
int kk=0;
void parser()
{
if (c==1) //begin
{
scanner();
yucu();
if (c==2) //end
{
scanner();
if (c==0 && kk==0)
printf("THIS STATEMENT IS RIGHT! \n");
}
else
{
if(kk!=1)
printf("Error,losing 'end' ! \n");
kk=1;
}
}else
{
printf("Error,losing 'begin' ! \n");
kk=1;
}
return;
}
void yucu()
{
statement();
while(c==26) //语句分割“;”
{
scanner();
statement();
}
return;
}
void statement()
{
if (c==6) //为标识符
{
scanner();
if (c==14) //为a :=
{
scanner();
expression();
}else if (c==2){
/*printf("THIS STATEMENT IS RIGHT\n");*/
}else if (c==26){
/*printf("THIS STATEMENT IS RIGHT\n");*/
}else
{
printf("Statement error:1!\n");
kk=1;
}
}
else
{
printf("Statement error:2!\n");
kk=1;
}
return;
}
void expression()
{
term();
while(c==15 || c==16)
{
scanner();
term();
}
return;
}
void term()
{
factor();
while(c==17 || c==18)
{
scanner();
factor();
}
return;
}
void factor()
{
if(c==6 || c==7) scanner(); //为标识符或整常数时读下一个单词符号
else if(c==27)
{
scanner();
expression();
if(c==28) scanner();
else {printf(" ')' 错误\n"); kk=1;}
}
else { printf("表达式错误\n"); kk=1;}
return;
}
void main()
{
p=0;
printf("********************语法分析程序***************\n");
printf("请输入源程序\n");
do
{
scanf("%c",&ch);
prog[p++]=ch;
}while(ch!='\n');
p=0;
scanner();
parser();
printf("语法分析结束! \n");
getchar();getchar();getchar();getchar();
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询