# include # include # include # include # include using namespace std;
int file(file *fp);
int shuxing()
return 0;
}int start()
int file(file *fp)
}system("cls");//清屏
system("color 1e"); //設
printf("\n>>>>>>>>>>檔案中的程式是!\n\n\n");
for(int a=0;a='a'&&ch<='z')||(ch>='a'&&ch<='z')||(ch>='0'&&ch<='9'))
else
}else}}
system("cls");//清屏
system("color 1e"); //設
printf("\n>>>>>>>>>拆分後單詞為:\n\n\n");
for(int i=1;i>>>>>>>>>拆分後單詞的屬性:\n\n");
char biao[100][30]=;
bool flag=0;
for(int i=1;i='0'&&word[i+1][0]<='9')
printf("%8s : <5,取餘運算子》\n",word[i]);
else
printf("%8s : <6,格式化字串》\n",word[i]);
}else if(strcmp(word[i],"*")==0||strcmp(word[i],"/")==0)
printf("%8s :<4,普通運算子》\n",word[i]);
else if(strcmp(word[i],">")==0||strcmp(word[i],"<")==0||strcmp(word[i],"=")==0)
else if(strcmp(word[i],"=")==0)
printf("%8s : <8,賦值運算子》\n",word[i]);
else
printf("%8s : <7,關係運算子》\n",word[i]);
}else if(strcmp(word[i],"!")==0)
else
printf("%8s : <9,邏輯非》\n",word[i]);
}else if (strcmp(word[i],"&")==0||strcmp(word[i],"|")==0)
else
printf("%8s : <10,邏輯運算的符》\n",word[i]);
}else if(strcmp(word[i],"(")==0||strcmp(word[i],")")==0||strcmp(word[i],"[")==0||strcmp(word[i],"]")==0||strcmp(word[i],"}")==0||strcmp(word[i],"
else
else if(word[i][h]=='.')
f=1;
}if(z)
}else
}if(!l)
printf("%8s : <13,標示符》\n",word[i]);}}
}}
}return 0;
}int main()
} printf("\n\n\t\t\t\t\t***按任意鍵繼續***\n");
getchar();
file(fp);
fclose(fp);
return 0;
}
編譯原理之詞法分析器(C C)
從乙個檔案中讀取原始碼,執行後可以直接看到結果,也可在指定檔案中檢視結果。這個詞法分析器只實現了部分關鍵字 字元等的識別,可在key陣列自行新增,種別碼的判別與新增用case更加方便,可寫下試試。include include include include include using namesp...
編譯原理 詞法分析器
1 從源程式檔案中讀入字元。2 統計行數和列數用於錯誤單詞的定位。3 刪除空格類字元,包括回車 製表符空格。4 按拼寫單詞,並用 內碼,屬性 二元式表示。屬性值 token 的機內表示 5 如果發現錯誤則報告出錯 6 根據需要是否填寫識別符號表供以後各階段使用 int tag 0 設立標誌 一開始本...
編譯原理,例 詞法分析器
編譯原理課作業要求自己寫乙個詞法分析器,我嘗試寫了一下。詞法分析 電腦科學中將字串行轉換為單詞 token 序列的過程。進行詞法分析的程式或者函式叫作詞法分析器 lexical analyzer 也叫掃瞄器 scanner 詞法分析器一般以函式的形式存在,供語法分析器呼叫。完成詞法分析任務的程式稱為...