資源簡介
要求完成的主要任務: (包括課程設計工作量及其技術要求,以及說明書撰寫等具體要求)
(1) 寫出符合給定的語法分析方法的文法及屬性文法。
(2) 完成題目要求的中間代碼四元式的描述。
(3) 寫出給定的語法分析方法的思想,完成語法分析和語義分析程序設計。
(4) 編制好分析程序后,設計若干用例,上機測試并通過所設計的分析程序。
(5) 設計報告格式按附件要求書寫。課程設計報告書正文的內容應包括:
1 系統描述(問題域描述);
2 文法及屬性文法的描述;
3 語法分析方法描述及語法分析表設計;
4 按給定的題目給出中間代碼形式的描述及中間代碼序列的結構設計;
5 編譯系統的概要設計;
6 詳細的算法描述(流程圖或偽代碼);
7 軟件的測試方法和測試結果;
8 研制報告(研制過程,本設計的評價、特點、不足、收獲與體會等);
9 參考文獻(按公開發表的規范書寫)。

代碼片段和文件信息
#include???
#include???
#include?
#include
#include
#include??
using???namespace???std;???
//*******************************************************************??
/*文法
S->for(A){G}
A->D?id?P
D->E?id?O?F
E->id=F
F->id
P->++|--
O->?<|>
G->GB
B->ID=S1
s1->TE1
T->FT1
E1->+TE1|&|-TE1
T1->*FT1|&|-TE1
X->B|&
*/
int?colume=0;//詞法分析當前行數
int?*ERROR=new?int?[100];
int?error=0;
int?file_siyuan_cow=1;//四元式文件輸出的行數
int?row=0;//記錄當前地址序列
int?t=0;//臨時變量標號
//字符串數組,保存詞法分析后的連續單詞
struct?tableword
{
string?word;
int?type;//1表示ID,2表示數值常量,3表示字符常量,0表示其它
};
//單詞序列?
tableword?table_word[100];
??int?tableword_length=0;
??int?word_now=0;//
struct?item
{
//int?sequence;//四元式序號
string?text;//四元式內容
//int?type;//0表示出口地址棧,1表示循環棧,-1表示正常四元式
//string?shift;//轉移到的目標地址
};
item?siyuanshi[100];
struct?Stack
{
int?size;
int?length;
string?*top;
string?*base;
};
struct?StackExit
{
int?size;
int?length;
int?*top;
int?*base;
};
??StackExit?exit1;//出口棧
??Stack?circle;//循環棧
??Stack?operater;//預算副棧
??Stack?operand;//操作數棧
//詞法分析相關函數
bool?Keyword(char?cstring?*KEYWORDint?KNLengthifstream?&infile);
bool?Identify(char?cifstream?&infilestring?&strtemp);
bool?ConstN(char?cifstream?&infile);
bool?ConstStr(char?cifstream?&infile);
bool?ConstChar(char?cifstream?&infile);
bool?ConstNum(char?cifstream?&infile);
bool?Operator(char?cifstream?&infile);
bool?Delimiter(char?c?);
int?classfify(char?c);
int?classify_num(char?c);
int?read(tableword?&word);
//棧的處理
void?InitStack(Stack?&stack);
void?Push(Stack?&stackstring?strtemp);
void?Pop(Stack?&stackstring?&stemp);
void?Gettop(Stack?&stackstring?&stemp);
void?InitStack(StackExit?&stack);
void?Push(StackExit?&stackint?temp);
void?Pop(StackExit?&stackint?&temp);
void?Gettop(StackExit?&stackint?&temp);
//*************************************************
//---------------語法語義函數
void?receive(tableword?&wordstring?tempint?type);
void?S(tableword?&word);
void?A(tableword?&word);
void?E(tableword?&word);
void?D(tableword?&word);
void?O(tableword?&word);
void?P(tableword?&word);
void?G(tableword?&word);
void?B(tableword?&word);
void?S1(tableword?&word);
void?X(tableword?&word);
void?E1(tableword?&word);
void?T(tableword?&word);
void?T1(tableword?&word);
void?F(tableword?&word);
//----------------------------------------------------
void?emit(int?rowstring?strtemp);
string?int_to_str(int?n);
char?Priority(string?op1string?op2?);
void?Menu();
void?Outtenspace(int?space_number);
void?output();
int?main()
{
??//讀出關鍵字
??string?KEYWORD[80];
??int?KNLength=0;
??ifstream?inf(“KEYWORD.txt“ios::in);
??if(!inf){cout<<“error“;exit(1);}
??int?i=0;
??while(inf>>KEYWORD[i])
??i++;
??KEYWORD[i]=“-1“;
??KNLength=i;
??inf.close();
??//********************************************
??//棧
????//初始化棧
??InitStack(exit1);
??InitStack(circle);
??InitStack(opera
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????31053??2010-01-08?09:33??for循環語句的翻譯\for循環語句.cpp
?????文件???????3467??2010-01-08?09:59??for循環語句的翻譯\for循環語句.dsp
?????文件????????530??2010-01-06?16:25??for循環語句的翻譯\for循環語句.dsw
?????文件????????538??2010-01-07?14:20??for循環語句的翻譯\KEYWORD.txt
?????文件????????157??2010-01-09?00:01??for循環語句的翻譯\procedure.txt
?????目錄??????????0??2010-01-09?22:26??for循環語句的翻譯
-----------?---------??----------?-----??----
????????????????35745????????????????????6
- 上一篇:計算機體系結構期末試卷及其答案
- 下一篇:用WIN32匯編寫的俄羅斯方塊
評論
共有 條評論