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

代碼片段和文件信息
//?C_Compiler1.cpp?:?定義控制臺應用程序的入口點。
//
#include?“stdafx.h“
#include
#include
#include
#include
#define?MYCOMPILER
#define?MAXWORD 10 //token和keyword最大長度
#define?MAXLENGTH 30
#define?MAXC 50 //符號表的最大容量
#define?MAXOP 500 //最大的操作指令條數
#define?MAXLEV 10 //最大的層數
#define?MAXF 10 //最多的實常量數
#define?MAXCASE 50
#define?MAXGO 100 //最大運行棧
#define?MAXGOLEV 10 //運行棧最大的調用層
#define MAXS 5 //printf語句中最多的轉換字符數
#define?MAXERROR 50
#define?kk 12 //關鍵詞個數
char?*Keyword[]={ //關鍵字
“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*/?“標識符或數字過長“
/*2*/?“非法單詞“
/*3*/?“缺少符號“
/*4*/?“缺少類型標識符“
/*5*/?“字符串過長或缺少符號“
/*6*/?“此處缺少運算的因子“
/*7*/?“符號表出界“
/*8*/?“標識符重復定義“
/*9*/?“此處應有‘=‘“
/*10*/?“變量使用出錯“
/*11*/?“無返回值函數不能用在此處“
/*12*/?“缺少“}”“
/*13*/?“缺少‘‘“
/*14*/?“無返回值函數不能有return語句“
/*15*/?“無主函數“
/*16*/?“函數調用時參數個數不對“
/*17*/?“缺少‘(‘“
/*18*/?“缺少‘)‘“
/*19*/?“編譯生成指令數過多“
/*20*/?“標識符未定義“
/*21*/?“轉換符用法錯誤為非變量型數據賦值“
/*22*/?“缺少“;”“
/*23*/?“缺少“{”“
/*24*/?“運行棧泄漏“
/*25*/?“函數調用超過了最大的層次數“
/*26*/?“函數返回值與函數類型不匹配“
/*27*/?“此處應為標識符“
/*28*/?“變量的類型和值的類型不匹配“
};
FILE?*FIN?*FOUT;??????????????????//輸入輸出文件指針
FILE?*EquFout;?????????????????????//四元式文件
FILE?*KeyWord;?????????????????????//關鍵字文件
FILE?*Oprate;??????????????????????//操作符文件
FILE?*Token;
char?Word[MAXWORD]; //store?token
int?num; //store?整數
char?sisstring[MAXLENGTH]; //store?字符串
int?sym; //store?標號;
char?cischar; //store?字符
char?fp[20]; //輸入文件名
int?linenum=1; //源程序行號
char?name[MAXC][MAXWORD]; //存標識符
int?NumOfC=1; //符號表內元素的個數
Character?Char[MAXC]; //符號表
int?numoflev[MAXLEV]; //各層的表中變量數
opr??opra[MAXOP]; //存指令
aopr?aop[MAXOP];
int?oprnum; //指令數
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];
//子函數說明
int?getsym(); //詞法分析程序
int?enter(int?levint?typeint?kind); //把變量填入符號表
//int?constdeclaration(); //分析常量說明部分
int?program(); //分析程序
int?charcheck(); //檢查標識符是否重復定義
//int?constdefine(?int?type?); //分析常量定義
int?vardefine(?int?type);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????59392??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\2_實驗項目指導書.doc
?????文件??????35328??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\5_實驗任務下達書.doc
?????文件??????94208??2007-02-11?01:01??灝忓瀷C璇█緙栬瘧鍣ㄨ璁1]\5_實驗設計方案.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個文件信息
- 上一篇:數據結構與算法分析C++版答案
- 下一篇:數值分析迭代法解非線性方程組c語言程序
評論
共有 條評論