编译原理——词法分析器
来源:互联网 发布:北京二手淘宝市场 编辑:程序博客网 时间:2024/05/02 00:07
这是个词法分析器的雏形.....嘿嘿
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct Lnode
...{
char data[20];
struct Lnode *next;
}Lnode,*LinkList;
LinkList symtable,consttable;
void CreateList(LinkList &L)
...{
L=(LinkList)malloc(sizeof(Lnode));
L->next=NULL;
}
void ListInsert(LinkList &L,int &number,char *strToken)
...{
LinkList p,s;
p=L;
number=1;
while (p->next)
...{
p=p->next;
number++;
}
s=(LinkList)malloc(sizeof(Lnode));
strcpy(s->data,strToken);
//s->next=p->next;
p->next=s;
s->next=NULL;
p=s;
}
char *keyword[32]=...{"auto","break","case","char","const","contunue","default","do",
"double","else","enum","extern", "float","for","goto","if",
"int","long","register","return","short","signed","sizeof","static",
"struct","switch","typedef","union","unsigned","void","volatile","while"
};
bool IsDigit(char ch)
...{//判断是否为字母
return(ch>='0'&&ch<='9');
}
bool IsLetter(char ch)
...{//判断是否为数字
return((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'));
}
void GetChar(FILE *fp,char &ch)
...{//将下一输入字符读到ch中
ch=fgetc(fp);
}
void GetBC(FILE *fp,char &ch)
...{//检查ch中的字符是否为空白,是空白则调用GetChar知道ch不是空白
while (ch==' '||ch==' '||ch==' ')
GetChar(fp,ch);
}
int Reserve(char *strToken)
...{//对strToken中的字符串查找保留字
int i;
for(i=1;i<=32;i++)
...{
if(!strcmp(keyword[i-1],strToken))
return i;
}
return 0;
}
void Concat(char *strToken,char ch)
...{//将ch中的字符链接到strToken之后
int i=0;
while (strToken[i]!='
#include <string.h>
#include <stdlib.h>
typedef struct Lnode
...{
char data[20];
struct Lnode *next;
}Lnode,*LinkList;
LinkList symtable,consttable;
void CreateList(LinkList &L)
...{
L=(LinkList)malloc(sizeof(Lnode));
L->next=NULL;
}
void ListInsert(LinkList &L,int &number,char *strToken)
...{
LinkList p,s;
p=L;
number=1;
while (p->next)
...{
p=p->next;
number++;
}
s=(LinkList)malloc(sizeof(Lnode));
strcpy(s->data,strToken);
//s->next=p->next;
p->next=s;
s->next=NULL;
p=s;
}
char *keyword[32]=...{"auto","break","case","char","const","contunue","default","do",
"double","else","enum","extern", "float","for","goto","if",
"int","long","register","return","short","signed","sizeof","static",
"struct","switch","typedef","union","unsigned","void","volatile","while"
};
bool IsDigit(char ch)
...{//判断是否为字母
return(ch>='0'&&ch<='9');
}
bool IsLetter(char ch)
...{//判断是否为数字
return((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'));
}
void GetChar(FILE *fp,char &ch)
...{//将下一输入字符读到ch中
ch=fgetc(fp);
}
void GetBC(FILE *fp,char &ch)
...{//检查ch中的字符是否为空白,是空白则调用GetChar知道ch不是空白
while (ch==' '||ch==' '||ch==' ')
GetChar(fp,ch);
}
int Reserve(char *strToken)
...{//对strToken中的字符串查找保留字
int i;
for(i=1;i<=32;i++)
...{
if(!strcmp(keyword[i-1],strToken))
return i;
}
return 0;
}
void Concat(char *strToken,char ch)
...{//将ch中的字符链接到strToken之后
int i=0;
while (strToken[i]!='
}
- 编译原理—词法分析器
- 编译原理——词法分析器
- 编译原理——词法分析器
- 编译原理——词法分析器
- 编译原理---词法分析器
- 编译原理词法分析器
- 编译原理 词法分析器
- 【编译原理】词法分析器
- 编译原理词法分析器
- 编译原理-词法分析器
- 编译原理词法分析器
- 编译原理词法分析器
- 编译原理--词法分析器
- 编译原理上机作业1——词法分析器
- 编译原理——Tiny词法分析器c++实现
- 编译原理----Lex词法分析器
- 词法分析器-2-编译原理
- 【编译原理】Lex词法分析器
- Android平台简介
- 编译原理——删除注释
- MD5加密代码(java)
- 堆溢出问题(-)
- ASP.NET 2.0 中跨网页提交的三种方法
- 编译原理——词法分析器
- VS2005的UserControl的使用问题
- 刘长炯老师的java 学习大草原
- nTune
- STN、TFT、OLED
- C#基础学习之二 文件读取
- c++ volatile用法
- ajax javascript post 方法实现(与C#混合使用)
- 流行技术我该学哪样?--给刚进入IT的朋友的一封信