freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

編譯原理課程設(shè)計--c-編譯器詞法分析與語法分析的實現(xiàn)-在線瀏覽

2025-03-06 01:33本頁面
  

【正文】 根據(jù)整理過后的語法規(guī)則來判斷語法樹的結(jié)點生成與走向。此處的難點在于語法規(guī)則的整理。最開始時我便參照著原29條語法規(guī)則來寫的,雖然全程序都沒有報錯,但是分析程序時一直分析不了。再不斷地在每一個結(jié)點生成時fprintf(listing,”\nits XXXX time\n”)一下,逐步排查錯誤,最終才確定了剩下的這25個語法規(guī)則。 。Header Files文件夾中包含: 。 。//根據(jù)書上原型做的,但根據(jù)語法規(guī)則所需要的,做過大量修改static int getNextChar(void) {}//根據(jù)書上原型做的,未經(jīng)修改static void ungetNextChar(void) {}//根據(jù)書上原型做的,未經(jīng)修改static struct {char* str。} reservedWords[MAXRESERVED] = {if,IF},{else,ELSE},{int,INT},{return,RETURN},{void,VOID},{while,WHILE}}。 static TreeNode * declaration_list(void)。 static TreeNode * params(void)。static TreeNode * param(void)。static TreeNode * local_declaration(void)。static TreeNode * statement(void)。static TreeNode * selection_stmt(void)。static TreeNode * return_stmt(void)。static TreeNode * var(void)。 static TreeNode * additive_expression(void)。 static TreeNode * factor(void)。static TreeNode * arg_list(void)。、詞法分析部分():其中部分代碼因為參照附錄B中內(nèi)容而未修改,所以略去。static struct { char* str。} reservedWords[MAXRESERVED] = {{if,IF},{else,ELSE},{int,INT},{return,RETURN},{void,VOID},{while,WHILE}}。 TokenType currentToken。 int save。 save = TRUE。//測試每一步狀態(tài) switch (state) { case START: if(isdigit(c)) state = INNUM。//是ID // fprintf(listing,\nis alpha\n)。/39。 state = INASSIGN_1。 } else if((c == 39。) || (c == 39。) || (c == 39。)) save = FALSE。39。 state = L_ASSIGN。39。 state = R_ASSIGN。=39。 state = E_ASSIGN。!39。 state = N_ASSIGN。 switch(c) { case EOF: save = FALSE。 break。,39。 break。=39。 break。+39。 break。39。 break。*39。 break。(39。 break。)39。 break。[39。 break。]39。 break。{39。 break。}39。 break。39。 break。 break。 case INCOMMENT: save = FALSE。 currentToken = ENDFILE。*39。//判斷 出 注釋 else state = INCOMMENT。 case INASSIGN_1: if (c == 39。) { // fprintf(listing,\nis zs\n)。 state = INCOMMENT。 ungetNextChar()。 } break。/39。 state = START。//不是,返回注釋 break。=39。 else currentToken = LT。 break。=39。 else currentToken = BT。 break。=39。 else currentToken = ASSIGN。 break。=39。 else ungetNextChar()。 break。 save = FALSE。 currentToken = NUM。 case INID: if (!isalpha(c)) { // fprintf(listing,\nis ID over\n)。 save = FALSE。 currentToken = ID。 case DONE: default: fprintf(listing,Scanner Bug: state = %d\n,state)。 currentToken = ERROR。 } // fprintf(listing,out switch)。 if ((save) amp。 (tokenStringIndex = MAXTOKENLEN)) tokenString[tokenStringIndex++] = (char) c。\039。 } } if (TraceScan) { fprintf(listing,\n%d: ,lineno)。 } return currentToken。TreeNode * stmt_program(void) { //program declarationlist TreeNode * t = declaration_list()。}TreeNode * declaration_list(void) { //declarationlist declarationlist declaration | declaration // declaration{declaration} TreeNode * t = NULL。 TreeNode * q = NULL。// fprintf(listing,\n+++++%s+++++\n,tokenString)。amp。 p = t。amp。 if(q!=NULL) { if(t == NULL) t = p = q。 p = q。}TreeNode * declaration(void) { //declaration vardeclaration | fundeclaration // (int|void) ID [[NUM]]。 | int a。| void main (void) | int gcd (int a[],int b) | { {vardeclaration} {statement(if,while...)} }//此處曾糾結(jié)過很久,最后發(fā)現(xiàn)附錄A開始陳列29條語法部分和后來詳解29條語法時有不同的地方。十分無語。我發(fā)現(xiàn)如果真的有vardeclaration那些東西又麻煩又累贅,就去掉了幾句語法 //amp。vardeclarationamp。type_specifieramp。fun_declaration TreeNode * t = newDecNode()。// fprintf(listing,\n+++++%s+++++\n,tokenString)。 match(INT)。 case VOID: t = void。 break。 default: syntaxError(unexpected token in Type )。 token = getToken()。 }// fprintf(listing,\n+++++%s+++++\n,tokenString)。 match(ID)。 switch(token) { case LPAREN_2: t = ArrayK。 match(RPAREN_2)。 break。 match(SEMI)。 case LPAREN_3: match(LPAREN_3)。 t = FunK。 match(RPAREN_3)。 if(t!=NULL) tchild[1] = pound_stmt()。 default: syntaxError(declaration wrong)。 break。}TreeNode * params(void) { TreeNode * t = newParamNode()。// fprintf(listing,\n+++++%s+++++\n,tokenString)。 match(VOID)。 default: t = UNull。 break。}TreeNode * param_list(void) { TreeNode * t = param()。// fprintf(listing,\nits par_l time\n)。 while ( (token != RPAREN_3) amp。 ( token != ENDFILE )) { TreeNode * q。 q = param()。 else { psibling = q。 } } } return t。//這是參數(shù)結(jié)點,區(qū)別與聲明結(jié)點// fprintf(listing,\nits param time\n)。 switch(token) { case VOID:// fprintf(listing,\n+++++VOID+++++\n)。 match(VOID)。 case INT: t = int。// fprintf(listing,\n+++++INT+++++\n)。 break。 syntaxError(param wrong)。 break。amp。 match(ID)。 t = Array。 } else t = Var。}TreeNode * pound_stmt(void) { TreeNode * t = newStmtNode(CompoundK)。// fprintf(listing,\n+++++%s+++++\n,tokenString)。 if( (t != NULL) amp。 (token == VOID || token == INT)) tchild[0] = local_declaration()。 match(RPAREN_1)。}TreeNode * local_declaration(void) { TreeNode * t = NULL。// fprintf(listing,\nits L_dec time\n)。 if(token == INT) { t = declaration()。 while(token == INT) { TreeNode * p = declaration()。 else { qsibling=p。 } } } } return t。 TreeNode * p。// fprintf(listing,\n+++++%s+++++\n,tokenString)。amp。 p = t。amp。 q = statement()。 else { psibling = q。 } } } } return t。// fprintf(listing,\nits exp_s time\n)。 if( token == SEMI ) { match(SEMI)。 match(SEMI)。}TreeNode * statement(void) { TreeNode * t = NULL。// fprintf(listing,\n+++++%s+++++\n,tokenString)。 t = expression_stmt()。 case LPAREN_1: // fprintf(listing,\nits pound_stmt() time\n)。 break。 t = selection_stmt()。 case WHI
點擊復(fù)制文檔內(nèi)容
環(huán)評公示相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1