資源簡介
基于c++編寫的編譯程序 有詞法分析 語法分析 語義分析以及目標(biāo)代碼生成

代碼片段和文件信息
//?C_Compiler1.cpp?:?定義控制臺應(yīng)用程序的入口點。
//
#include?“stdafx.h“
#include
#include
#include
#include
#define?MYCOMPILER
#define?MAXWORD 10 //token和keyword最大長度
#define?MAXLENGTH 30
#define?MAXC 50 //符號表的最大容量
#define?MAXOP 500 //最大的操作指令條數(shù)
#define?MAXLEV 10 //最大的層數(shù)
#define?MAXF 10 //最多的實常量數(shù)
#define?MAXCASE 50
#define?MAXGO 100 //最大運行棧
#define?MAXGOLEV 10 //運行棧最大的調(diào)用層
#define MAXS 5 //printf語句中最多的轉(zhuǎn)換字符數(shù)
#define?MAXERROR 50
#define?kk 12 //關(guān)鍵詞個數(shù)
char?*Keyword[]={ //關(guān)鍵字
“const““int““char““void“
“main““if““else“?“do““while“
“scanf““printf“?“return“
};
char?*oprate[]={ //操作碼
“““““JME““JMC““JMP““CAS“
“RED““EXF““WRI““““:+““:-“““
“:*““:/““MUS“?“j>“?“j<“??“j==“
“j!=“??“j>=“?“j<=““““CAL““BEGIN“
“END““:=“
};
union?Cha{
int?num;
char?cischar;
};
struct?Character{ //符號表
char?*name?;
int?typelevadrkind;
Cha?uchar;
};
struct?opr{ //中間代碼
int?opop1op2result;
};
struct?aopr{
int?anumad1;
};
char*?err_msg[]?= //定義出錯提示信息
{
/*0*/?““
/*1*/?“標(biāo)識符或數(shù)字過長“
/*2*/?“非法單詞“
/*3*/?“缺少符號“
/*4*/?“缺少類型標(biāo)識符“
/*5*/?“字符串過長或缺少符號“
/*6*/?“此處缺少運算的因子“
/*7*/?“符號表出界“
/*8*/?“標(biāo)識符重復(fù)定義“
/*9*/?“此處應(yīng)有‘=‘“
/*10*/?“變量使用出錯“
/*11*/?“無返回值函數(shù)不能用在此處“
/*12*/?“缺少“}”“
/*13*/?“缺少‘‘“
/*14*/?“無返回值函數(shù)不能有return語句“
/*15*/?“無主函數(shù)“
/*16*/?“函數(shù)調(diào)用時參數(shù)個數(shù)不對“
/*17*/?“缺少‘(‘“
/*18*/?“缺少‘)‘“
/*19*/?“編譯生成指令數(shù)過多“
/*20*/?“標(biāo)識符未定義“
/*21*/?“轉(zhuǎn)換符用法錯誤為非變量型數(shù)據(jù)賦值“
/*22*/?“缺少“;”“
/*23*/?“缺少“{”“
/*24*/?“運行棧泄漏“
/*25*/?“函數(shù)調(diào)用超過了最大的層次數(shù)“
/*26*/?“函數(shù)返回值與函數(shù)類型不匹配“
/*27*/?“此處應(yīng)為標(biāo)識符“
/*28*/?“變量的類型和值的類型不匹配“
};
FILE?*FIN?*FOUT;??????????????????//輸入輸出文件指針
FILE?*EquFout;?????????????????????//四元式文件
FILE?*KeyWord;?????????????????????//關(guān)鍵字文件
FILE?*Oprate;??????????????????????//操作符文件
FILE?*Token;
char?Word[MAXWORD]; //store?token
int?num; //store?整數(shù)
char?sisstring[MAXLENGTH]; //store?字符串
int?sym; //store?標(biāo)號;
char?cischar; //store?字符
char?fp[20]; //輸入文件名
int?linenum=1; //源程序行號
char?name[MAXC][MAXWORD]; //存標(biāo)識符
int?NumOfC=1; //符號表內(nèi)元素的個數(shù)
Character?Char[MAXC]; //符號表
int?numoflev[MAXLEV]; //各層的表中變量數(shù)
opr??opra[MAXOP]; //存指令
aopr?aop[MAXOP];
int?oprnum; //指令數(shù)
int?go[MAXGO]; //運行棧
int?dl[MAXGOLEV]bl[MAXGOLEV]; //運行棧輔助指針
int?errornum=0error[MAXERROR]errorline[MAXERROR];
int?gonum=0dlnum=0blnum=0;
int?type=0;
int?snum=0;
int?start;
int?lev=1;
int?breakoprIsbreak=0;
int?typeofexp1=11?typeofexp2=12;
int?oprnumcase=0;
int?Isret=1;
int?adr[MAXC];
int?ad=0;
int?ab=0;
int?gsym[MAXC];
int?sy=0;
int?A=0;
int?adr1[MAXC];
//子函數(shù)說明
int?getsym(); //詞法分析程序
int?enter(int?levint?typeint?kind); //把變量填入符號表
//int?constdeclaration(); //分析常量說明部分
int?program(); //分析程序
int?charcheck(); //檢查標(biāo)識符是否重復(fù)定義
//int?constdefine(?int?type?); //分析常量定義
int?vardefine(?int?type);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????59392??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\2_實驗項目指導(dǎo)書.doc
?????文件??????35328??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\5_實驗任務(wù)下達(dá)書.doc
?????文件??????94208??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\5_實驗設(shè)計方案.doc
?????文件?????155648??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\exe\C_compiler.exe
?????文件?????511036??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\exe\C_compiler.ilk
?????文件?????429056??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\exe\C_compiler.pdb
?????文件??????????0??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\exe\equfout.txt
?????文件????????112??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\exe\keyword.txt
?????文件????????205??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\exe\oprate.txt
?????文件?????????85??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\exe\readme.txt
?????文件?????????88??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\exe\test.txt
?????文件?????????78??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\exe\test1.txt
?????文件?????????78??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\exe\test2.txt
?????文件????????120??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\exe\test3.txt
?????文件??????37198??2007-07-05?00:20??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\project\C_compiler.cpp
?????文件???????3449??2007-07-04?23:49??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\project\C_compiler.dsp
?????文件????????545??2007-07-05?00:41??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\project\C_compiler.dsw
?????文件??????41984??2007-07-05?00:41??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\project\C_compiler.ncb
?????文件??????48640??2007-07-05?00:41??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\project\C_compiler.opt
?????文件????????766??2007-07-05?00:21??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\project\C_compiler.plg
?????文件???????4496??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\project\C_compiler.vcproj
?????文件???????1427??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\project\C_compiler.vcproj.81263482F9D9484.Administrator.user
?????文件???????1427??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\project\C_compiler.vcproj.81263482F9D9484.aijun.user
?????文件???????1407??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\project\C_compiler.vcproj.AIJUN.aijun.user
?????文件??????19250??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\project\Debug\BuildLog.htm
?????文件?????200809??2007-07-05?00:21??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\project\Debug\C_compiler.exe
?????文件????????403??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\project\Debug\C_compiler.exe.em
?????文件????????468??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\project\Debug\C_compiler.exe.em
?????文件????????385??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\project\Debug\C_compiler.exe.intermediate.manifest
?????文件?????215528??2007-07-05?00:21??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\C_compiler\project\Debug\C_compiler.ilk
............此處省略26個文件信息
評論
共有 條評論