資源簡介
IF-ELSE條件語句的翻譯程序設計(LR方法、輸出三地址表示)

代碼片段和文件信息
#include“declare.h“
#include
#include
//...............................ListManager................................//
ListManager::ListManager(){
//初始化關鍵字表
keyList.push_back(“begin“)?;
keyList.push_back(“call“)?;
keyList.push_back(“const“)?;
keyList.push_back(“do“)?;
keyList.push_back(“end“)?;
keyList.push_back(“if“)?;
keyList.push_back(“true“)?;
keyList.push_back(“false“)?;
keyList.push_back(“else“)?;
keyList.push_back(“odd“)?;
keyList.push_back(“procedure“)?;
keyList.push_back(“read“)?;
keyList.push_back(“then“)?;
keyList.push_back(“var“)?;
keyList.push_back(“while“)?;
keyList.push_back(“write“)?;
//初始化操作符表
optrList.push_back(‘+‘)?;
optrList.push_back(‘-‘)?;
optrList.push_back(‘*‘)?;
optrList.push_back(‘/‘)?;
optrList.push_back(‘(‘)?;
optrList.push_back(‘)‘)?;
optrList.push_back(‘=‘)?;
optrList.push_back(‘>‘)?;
optrList.push_back(‘<‘)?;
optrList.push_back(‘|‘)?;
optrList.push_back(‘&‘)?;
optrList.push_back(‘!‘)?;
//初始化分界符表
splitList.push_back(‘‘)?;
splitList.push_back(‘.‘)?;
splitList.push_back(‘#‘)?;
splitList.push_back(‘;‘)?;
}
int?ListManager::containsKeyWord(string?str){
//判斷是否是關鍵字
for(int?i?=?0;i if(str?==?keyList.at(i)){
return?KEY?;
}
}
return?-1?;
}
int?ListManager::containsOptr(char?ch){
//判斷是否是一個操作符
for(int?i?=?0;i ? if(ch?==?optrList.at(i)){
return?OPTR?;?
}
}
return?-1?;?
}
int?ListManager::containsSplit(char?ch){
//判斷是否是分界符
for(int?i?=?0;i if(ch?==?splitList.at(i)){
return?SPLIT?;?
}
}
return?-1?;
}
//..........functions............//
string?GetFileName(){
string?fileName?;
cout<<“******Please?input?the?file?name?you?wanto?compile?it!******“< ? cin>>fileName?;
cin.ignore()?;
return?fileName?;
}
string?GetNextLine(ifstream&?fin){
string?line?;
if(getline(finline)){
return?line?;
}
return?“0_NO_0“;?//用來判斷是否到末尾
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????95??2010-01-07?20:01??CompilerPro1\test.txt
?????文件????????104??2010-01-07?20:46??CompilerPro1\test1.txt
?????文件????????207??2010-01-07?22:09??CompilerPro1\lexout.txt
?????文件???????1072??2010-01-07?20:50??CompilerPro1\lr_ds.h
?????文件????????847??2010-01-07?14:03??CompilerPro1\declare.h
?????文件???????2073??2010-01-07?18:41??CompilerPro1\declare.cpp
?????文件??????54784??2010-01-10?18:37??CompilerPro1\CompileExp1.opt
?????文件????????530??2009-11-07?10:02??CompilerPro1\CompileExp1.dsw
?????文件???????1437??2010-01-07?22:09??CompilerPro1\CompileExp1.plg
?????文件?????????71??2010-01-07?22:09??CompilerPro1\dd.txt
?????文件??????74752??2010-01-10?18:37??CompilerPro1\CompileExp1.ncb
?????文件???????4655??2010-01-07?11:46??CompilerPro1\CompileExp1.dsp
?????文件?????123904??2010-01-07?22:09??CompilerPro1\Debug\vc60.idb
?????文件?????192512??2010-01-07?22:09??CompilerPro1\Debug\vc60.pdb
?????文件????3390720??2010-01-07?20:51??CompilerPro1\Debug\CompileExp1.pch
?????文件?????387002??2010-01-07?22:09??CompilerPro1\Debug\lr_ds_impl.obj
?????文件?????379738??2010-01-07?20:51??CompilerPro1\Debug\MainThread.obj
?????文件?????749671??2010-01-07?22:09??CompilerPro1\Debug\CompileExp1.exe
?????文件????1696768??2010-01-07?22:09??CompilerPro1\Debug\CompileExp1.pdb
?????文件??????44166??2010-01-07?20:51??CompilerPro1\Debug\sem_impl.obj
?????文件??????????0??2009-11-19?13:01??CompilerPro1\Debug\out.txt
?????文件????1167756??2010-01-07?22:09??CompilerPro1\Debug\CompileExp1.ilk
?????文件?????197348??2010-01-07?18:41??CompilerPro1\Debug\declare.obj
?????文件??????????0??2010-01-07?21:18??CompilerPro1\Debug\lexout.txt
?????文件???????7393??2010-01-07?15:19??CompilerPro1\MainThread.cpp
?????文件????????357??2010-01-07?20:48??CompilerPro1\sem_impl.cpp
?????文件????????103??2010-01-07?21:03??CompilerPro1\test2.txt
?????文件??????35315??2010-01-07?21:07??CompilerPro1\lr_ds_impl.cpp
?????目錄??????????0??2010-01-04?23:02??CompilerPro1\Debug
?????目錄??????????0??2010-01-04?23:02??CompilerPro1
............此處省略3個文件信息
評論
共有 條評論