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

  • 大小: 8KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-07-26
  • 語言: 其他
  • 標簽: 編譯原理??

資源簡介

編譯原理課程設計之編譯器(完整代碼 + 測試樣例):包含了完整的編譯器源代碼和測試樣例,內容上實現了一體化的詞法分析 + 語法分析 + 語法制導翻譯,最后生成對應匯編指令

資源截圖

代碼片段和文件信息

#include?
using?namespace?std;
const?int?maxn?=?1002;
const?int?n_key?=?41;
const?int?n_oper?=?21;

char?c;

string?key_word[n_key]?=?{“auto“?“enum“?“restrict“?“unsigned“?“break“
????????????????????“extern“?“return“?“void“?“case“?“float“
????????????????????“short“?“volatile“?“char“?“for“?“signed“
????????????????????“while“?“const“?“goto“?“sizeof“?“_Bool“
????????????????????“continue“?“if“?“static“?“_Complex“?“default“
????????????????????“inline“?“struct“?“_Imaginary“?“do“?“int“
????????????????????“switch“?“double“?“long“?“typedef“?“else“
????????????????????“register“?“union“?“scanf“?“printf“?“cin“
????????????????????“cout“
};

string?oper[]?=?{“+“?“-“?“*“?“/“?“^“
????????????????“<“?“>“?“++“?“--“?“==“
????????????????“*=“?“/=“?“>=“?“<=“?“<<“
????????????????“>>“?“>>=“?“<<=“?“%“?“&“
????????????????“^“
};

char?bound[]?=?{‘‘?‘;‘?‘(‘?‘)‘?‘[‘?‘]‘?‘{‘?‘}‘};

struct?Word{????????????????//詞結構體
????int?id;
????string?value;
};

struct?Num{
????int?id;
????int?vi;
????double?vd;
};
Num?n[maxn];????????//數字
Word?w[maxn];???????//詞
map?m;????//標識符
int?f?=?0?ff?=?0;



//語法分析
typedef?pair?P;
map?pre_list;
typedef?set?Sets;
map?first?follow?wenfa?select;??????//first?follow
Sets?Term?Nterm;????????????????//終極符,非終極符
string?Start;

typedef?struct?node{
????string?value;
????string?type;
????int?number;
}pro;
vector?watest;





//translation翻譯

//詞法分析
bool?is_oper(string?s){
????for(int?i=0;?i????return?false;
}

bool?is_bound(char?c){
????for(int?i=0;?i????return?false;
}

bool?is_key(string?s){
????for(int?i=0;?i????return?false;
}

int?stoi(string?s){?????????????????????????//get?int
????int?ans?=?0;
????for(int?i=0;?i????return?ans;
}

double?stof(string?s){??????????????????????//get?double
????long?long?ans?=?0;
????int?fd?=?-1?fe?=?-1;
????for(int?i=0;?i????????if(s[i]?==?‘.‘){
????????????fd?=?i;
????????????continue;
????????}
????????if(s[i]?==?‘e‘){
????????????fe?=?i;
????????????continue;
????????}
????????ans?=?ans?*?10?+?s[i]?-?‘0‘;
????}
????if(fd?!=?-1?&&?fe?==?-1)?return?double(ans)/(pow(10?s.size()?-?fd?-?1));
????else?if(fd?==?-1?&&?fe?!=?-1){
????????long?long?temp?=?ans?%?(long?long)pow(10?s.size()?-?fe?-?1);?????//得到e后的數字
????????ans?/=?pow(10?s.size()?-?fe?-?1);??????????????????????????//得到e前的數字
????????return?double(ans*pow(10?temp));
????}
????else{
????????long?long?temp?=?ans?%?(long?long)pow(10?s.size()?-?fe?-?1);?????//得到e后的數字
????????cout<????????ans?/=?pow(10?s.size()?-?fe?-?1);???????????????????????

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-07-29?15:44??編譯器\
?????文件????????1617??2015-06-25?19:21??編譯器\grammar.txt
?????文件?????????193??2015-06-25?15:36??編譯器\programe.txt
?????文件???????34619??2015-07-02?10:16??編譯器\word_grammar_translation.cpp

評論

共有 條評論