首页 > 代码库 > 词法分析程序
词法分析程序
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 100
int a=1;
long g=0;
char nchar[N]
int k=0;
char ch=NULL;
char m[30]={""};
int sym=-1;
main()
{
char cr;
int n;
printf("请输入一串字符串:");
while((cr=getchar())!=‘$‘)
{
nchar[g]=cr;
g++;
}
do
{
n=getsym();
}while(n);
}
int getsym()
{
int i;
char a[2]={""};
char word[][15]={"begin","do","end","if","then","while"};
int wsym[6]={1,2,3,4,5,6};
int ssym[9]={25,26,27,28,0,13,14,15,16};
char b[9]={‘=‘,‘;‘,‘(‘,‘)‘,‘#‘,‘+‘,‘-‘,‘*‘,‘/‘};
if(a==1&&k<g)
{
ch=nchar[k];
j++;
k++;
}
while(ch==‘ ‘||ch==10||ch==9||ch==13)
{
if(k==g)
{
return 0;
}
ch=nchar[k];
k++;
}
用文法描述词法规则
C->1|2|3|…|9
词法分析程序