陕西师范大学 编译原理 实验报告
实验名称:词法分析程序实验
一、源程序:
#include <iostream>
#include<string>
using namespace std;
#dene MAX 22
char ch =' ';
string key[6]={"DIM","IF","DO","STOP","END","BEGIM"};
string arr="";
FILE * fpin;
void analyse();
int Iskey(string c){ //关键字判断
int i;
for(i=0;i<6;i++)
{
if(key[i].compare(c)==0) return 1;
} return 0;
}
int IsLetter(char c) //判断是否为字母
{
if(((c<='z')&&(c>='a'))||((c<='Z')&&(c>='A'))) return 1;
else return 0;
}
int IsDigit(char c){ //判断是否为数字
if(c>='0'&&c<='9') return 1;
else return 0;
}
void advance()
{
fseek(fpin,-1L,SEEK_CUR);
}
bool GetBC()
{
if(ch==' '||ch==' '||ch=='')
return true;