91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 23KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2023-07-19
  • 語言: 其他
  • 標簽: Lex,編譯??

資源簡介

seuLex Lex輸入文件的解析 正規表達式的解析 一個正規表達式到NFA的轉換算法實現 多個NFA的合并 NFA的確定化和最小化算法實現 返回狀態與返回內容的對應 SeuLex應用

資源截圖

代碼片段和文件信息

#include
#include?
#include//文件流
#include
#include//棧
#include//容器
#include//鏈表
#include
#include
#include
using?namespace?std;

#define?DEFINE_HEAD?41//定義段開始標識“%{”
#define?DEFINE_END?42//定義段結束標識“%}”
#define?RULE_ID?43//規則段標識“%%”

#define?ERROR?-11//錯誤
#define?EPSLONG?-1//????????????????


ifstream?readfile;

ofstream?writefile;
ofstream?writeReActNFA;
ofstream?writeNFA;
ofstream?writeDFA;


int?lineno=0;//lex文件當前行數信息
static?int?nfaindex=1;


struct??node
{
int?label;
int?acceptstatetag;
multimap?next;
};


map?id2reTable;?//存儲定義段中標識名到正則式的映射
map?precedence;//存儲操作符的優先級

vector?actionTable;//存儲action內對應內容

list??nfas;//存儲每個正則式的NFA;
list?finalNFA;//最終的nfa
list?DFA;

vector?nfa;
vector?dfa;
mapint?>?dfanodetable;
map?nfaTer2Action;
map?dfaTer2Action;

int?checkType(char?c);//lex文件結構的解析
pairtakeApart(string?&str);//規則段re和action
void?replaceID(string?&re);//lex文件中正規表達式標志id替換成正規表達式re
void?Change(char?*char?*);//將中綴表達式變成后綴表達式
void?Initprecedence();//初始化中綴表達式中操作符的優先級
void?generateNFA(char?*relist??nodes);?//由re產生NFA
void?joinNFA(list??onenfalist?finalnfa);
bool?isLetter?(char);//判斷是否是字母
void?NFA2DFA(list?bignfa);
void?Eclosure(set?&t);//求E閉包
set?move(const?set?&Ichar?onesymbol);
void?genAnalysisCode();//生成條件控制表示的DFA的代碼


void?main(){
Initprecedence();//給操作符初始化優先級
cout<<“SeuLex?project:“< cout<<“Open?the?source?lex?file?:?lex.l\n\n“;
readfile.open(“lex.l“ios::in);

cout<<“Open?the?destination?files:\n“;
cout<<“1----------The??lexer??program?.cpp?file?:?yylex.cpp\n“;
writefile.open(“yylex.cpp“ios::out);
cout<<“2--The?relationship?of?RE-Action-NFA?:Re_Act_NFA.txt\n“;
writeReActNFA.open(“Re_Act_NFA.txt“ios::out);
cout<<“3--------------------The?join?together?NFA?:?NFA.txt\n“;
writeNFA.open(“NFA.txt“ios::out);
cout<<“4--------------Mini?the?NFA?we?can?get?DFA?:?DFA.txt\n“;
writeDFA.open(“DFA.txt“ios::out);

cout<
//*********************************
//掃描定義段:“%{?”和?“%}”?之間
char?c=readfile.get();
int??type=checkType(c);//定義段?規則段?
if(type!=DEFINE_HEAD)
{
cout<<“Error!The?lex.l?file?dismatch?the?lex?grammar?!\n“;//不符合lex文件語法
return;
}

????writefile<<“//lex文件定義段直接拷貝開始:“;
while(!readfile.eof()&&type!=DEFINE_END)//掃描過程
{
c=readfile.get();
if(c==‘\t‘)?continue;
if(c==‘\n‘)?lineno++;//lineno:lex文件當前行數
if(c==‘%‘)?{type=checkType(c);continue;}//結尾DEFINE_END?%}嗎

writefile.put(c);//逐個字符的寫入目標文件
}
writefile<<“//lex文件定義段拷貝結束:“<


//*********************************************************
//掃描正規表達式:該部分由用戶自定義標示id和正規表達式re組成


pair?userDefineID;//〈idre〉
type=0;

//開始識別正規表達式對〈idre〉
c=readfile.get();

while(!readfile.eof()&&type!=R

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件??????39424??2010-05-18?22:24??09007412LEX.doc

?????文件??????16343??2010-05-06?22:53??DFA.txt

?????文件???????1422??2010-05-06?23:08??lex.l

?????文件??????13511??2010-05-06?22:53??NFA.txt

?????文件??????11992??2010-05-06?22:53??Re_Act_NFA.txt

?????文件??????23344??2010-05-06?23:04??SeuLex.cpp

?????文件??????48576??2010-05-06?22:53??yylex.cpp

?????文件????????702??2003-01-01?13:25??yytab.h

-----------?---------??----------?-----??----

???????????????155314????????????????????8


評論

共有 條評論

相關資源