编译技术实现——词法分析
2004-07-31 09:40
197 查看
要做编译技术的实习了,想到csdn找几片相关的文章看看
没找到呀,这方面的也许很少
所以把我自己写的词法分析的源代码贴出来了
希望大家批评指正
#include "stdlib.h"
#include "stdio.h"
#include "iostream.h"
#include "fstream.h"
#include "string.h"
#include "ctype.h"
#include "malloc.h"
#define $ID 0
#define $ID_INT 1
#define $ID_CHAR 2
#define $ID_FLOAT 3
#define $ID_VOID 4
#define $ID_CONST 5
#define $ID_STATIC 6
#define $ID_IF 7
#define $ID_ELSE 8
#define $ID_DO 9
#define $ID_WHILE 10
#define $ID_SWITCH 11
#define $ID_CASE 12
#define $ID_DEFAULT 13
#define $ID_BREAK 14
#define $ID_CONTINUE 15
#define $ID_RETURN 16
#define $ID_DEFINE 17
#define $ID_INCLUDE 18
#define $INT 19
#define $ASSIGN 20
#define $ADD 21
#define $SUB 22
#define $MUL 23
#define $DIV 24
#define $LPAR 25
#define $RPAR 26
#define $LPAR_DIM 27
#define $RPAR_DIM 28
#define $LPAR_SEN 29
#define $RPAR_SEN 30
#define $EQUAL 31
#define $NOT_EQUAL 32
#define $LT 33
#define $GT 34
#define $LT_EQUAL 35
#define $GT_EQUAL 36
#define $COMMA 37
#define $DOT 38
#define $INTDIV 39
#define $COMMENT 40
#define $COMMENT_ASSIGN 41
#define $SENEND 42
#define $QUESTION 43
#define $NOT 44
struct Token
{
int ncode;
char *ntoken;
};
//////////////数组维数表及其处理
struct Dim
{
int uprange1;
int uprange2;
}Dim_table[20];
int Dimtable_index;
void Dimtable_Initiate()
{
for(int i=0;i<20;i++)
{
Dim_table[i].uprange1=0;
Dim_table[i].uprange2=0;
}
}
void Dimtable_Print()
{
cout<<"The CONTENTS of the Dim_table:/n";
for(int i=0;i<20;i++)
{
cout< for(int i=0;i<100;i++)
{
cout<<"i:="< int i=strlen(token);
//cout<
没找到呀,这方面的也许很少
所以把我自己写的词法分析的源代码贴出来了
希望大家批评指正
#include "stdlib.h"
#include "stdio.h"
#include "iostream.h"
#include "fstream.h"
#include "string.h"
#include "ctype.h"
#include "malloc.h"
#define $ID 0
#define $ID_INT 1
#define $ID_CHAR 2
#define $ID_FLOAT 3
#define $ID_VOID 4
#define $ID_CONST 5
#define $ID_STATIC 6
#define $ID_IF 7
#define $ID_ELSE 8
#define $ID_DO 9
#define $ID_WHILE 10
#define $ID_SWITCH 11
#define $ID_CASE 12
#define $ID_DEFAULT 13
#define $ID_BREAK 14
#define $ID_CONTINUE 15
#define $ID_RETURN 16
#define $ID_DEFINE 17
#define $ID_INCLUDE 18
#define $INT 19
#define $ASSIGN 20
#define $ADD 21
#define $SUB 22
#define $MUL 23
#define $DIV 24
#define $LPAR 25
#define $RPAR 26
#define $LPAR_DIM 27
#define $RPAR_DIM 28
#define $LPAR_SEN 29
#define $RPAR_SEN 30
#define $EQUAL 31
#define $NOT_EQUAL 32
#define $LT 33
#define $GT 34
#define $LT_EQUAL 35
#define $GT_EQUAL 36
#define $COMMA 37
#define $DOT 38
#define $INTDIV 39
#define $COMMENT 40
#define $COMMENT_ASSIGN 41
#define $SENEND 42
#define $QUESTION 43
#define $NOT 44
struct Token
{
int ncode;
char *ntoken;
};
//////////////数组维数表及其处理
struct Dim
{
int uprange1;
int uprange2;
}Dim_table[20];
int Dimtable_index;
void Dimtable_Initiate()
{
for(int i=0;i<20;i++)
{
Dim_table[i].uprange1=0;
Dim_table[i].uprange2=0;
}
}
void Dimtable_Print()
{
cout<<"The CONTENTS of the Dim_table:/n";
for(int i=0;i<20;i++)
{
cout< for(int i=0;i<100;i++)
{
cout<<"i:="< int i=strlen(token);
//cout<
相关文章推荐
- 一起谈.NET技术,微博是个大金矿,使用VS2010编译QOAuth支持微博通用认证OAuth实现SINA微博登陆
- C++ 接口与实现分离技术---如何将文件间的编译关系降至最低
- PL/0语言编译程序整理实现:(3)、词法分析
- C#反射技术实现代码编译
- HTTP Live Streaming直播(iOS直播)技术分析与实现
- Cocos2d-x使用Luajit将Lua脚本编译为bytecode,从而实现加密
- 实现聊天室在线人员无刷新所需要的JavaScript技术 - 1
- frameset 实现无刷新聊天室技术实现方法
- 多播(组播)与广播的技术实现
- 分页技术原理与实现之分页的意义及方法(一)
- 端口复用技术与实现代码
- EJB是基于哪些技术实现的_SessionBean和EntityBean的区别_StatefulBean和StatelessBean的区别_JAVA面试题及答案
- 利用反射技术实现POJO的数据库操作
- Qt实现zip压缩和解压,编译、调用zlib和QuaZip动态库过程详解
- 分页技术原理与实现之Java+Oracle代码实现分页(二)
- 负载均衡主要的实现技术
- Apache中URL Rewrite技术的实现
- 实现RTSP摄像机进行网页直播和微信直播的技术方案:EasyNVR自动更新方法
- MFC中对象序列化技术的实现