您的位置:首页 > 其它

编译技术实现——词法分析

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<
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: