编译原理
.代码如下:
#include<stdio.h> #include<string.h> char ch;
char token[20],prog[20]; int i,p,c;
char *keyword[5]={"while","if","else","switch","case"}; int reserve() //判断是否为保留字 {
if(strcmp(token,keyword[0])==0) return 1;
else if(strcmp(token,keyword[1])==0) return 2;
else if(strcmp(token,keyword[2])==0) return 3;
else if(strcmp(token,keyword[3])==0) return 4;
else if(strcmp(token,keyword[4])==0) return 5; else return 0; }
int letter() //判断是否为字母 {
if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z') return 1; else return 0; }
int digit() //判断是否为数字 {
if(ch>='0'&&ch<='9') return 1; else return 0; }
int retract() //指针回退一个字 {
p=p-1; }
void get() {
ch=prog[p]; p++; }