#include<iostream.h>
#include<ctype.h>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#define ID 6
#define INT 7
#define LT 8
#define LE 9
#define EQ 10
#define NE 11
#define GT 12
#define GE 13
#define FZ 14
#define DEV 15
strUCt KeyWord //关键字结构
{
char *word;
int id;
};
KeyWord keyword[]={ //关键字数组
,
,
,
,
,
,
,
};
char TOKEN[20];
int graphnum=1; //记录错误所在的位置
int lookup(char *string);
void out(int id ,char *string);
void report_error(char ERR_CH);
bool isalpha(char c) ;
bool isdigit(char c);
bool isalnum(char c);
void scanner_example(FILE *fp);
int lookup(char *string)
{
for(int i=0;i<sizeof(keyword)/sizeof(KeyWord);i++)
{
if(strcmp(string,keyword[i].word)==0)
return keyword[i].id;
}
return 0;
}
void out(int id ,char *string)
{
printf("(%d,%s) ",id,string);;
}
void report_error(char ERR_CH) //错误处理程序
{
printf("undeclared identifler %c int %d line! ",ERR_CH,graphnum);
}
bool isalpha(char c)
{
if( (c>='a'&&c<='z') (c>='A'&&c<='Z') )
return true;
else
return false;
}