資源簡介
該詞法分析器在VS2012下開發(fā)(C#語言),實(shí)現(xiàn)了基本的C語言詞法成分的分析功能,并且可以發(fā)現(xiàn)錯(cuò)誤和指出錯(cuò)誤類型,支持一件導(dǎo)入導(dǎo)出外部代碼文件和詞法分析結(jié)果,關(guān)鍵是界面美觀~Ps(哈工大軟件學(xué)院編譯原理第一次實(shí)驗(yàn))
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
using?System.Runtime.InteropServices;
using?System.IO;
namespace?Lex_sunfiyes
{
????public?partial?class?Form1?:?Form
????{
????????#region?全局變量
????????char[]?program;//代碼存放在字符數(shù)組中
????????char[]?token?=?new?char[256];//標(biāo)示符數(shù)組
????????char[]?trans?=?{?‘n‘‘r‘‘0‘‘t‘‘v‘‘b‘‘f‘‘a(chǎn)‘‘“‘‘\‘‘‘\\‘};??//11個(gè)轉(zhuǎn)義字符表
????????char?ch;??//臨時(shí)字符
????????string[]?type?=?{?“IDN“?“AUTO“?“BREAK“?“CASE“?“CHAR“?“CONST“?
????????????????????????????“CONTINUE“?“DEFAULT“?“DO“?“DOUBLE“?
????????????????????????????“ELSE“?“ENUM“?“EXTERN“?“FLOAT“?“FOR“?
????????????????????????????“GOTO“?“IF“?“INT“?“LONG“?“REGISTER“?
????????????????????????????“RETURN“?“SHORT“?“SINGED“?“SIZEOF“?“STATIC“?
????????????????????????????“STRUCT“?“SWITCH“?“TYPEDEF“?“UNION“?“UNSINGED)“?
????????????????????????????“VOID“?“VOLATILE“?“WHILE““CONST_INT““CONST_FLOAT“
????????????????????????????“CONST_DOUBLE““CONST_CHAR““CONST_STRING““BSLP““BSRP““MSLP““MSRP“
????????????????????????????“SLP““SRP““TILDE““COMMA““SEM““POINT““WELL““QUE““COL““LSHIFT““RSHIFT““LESS““LESSEQU“
????????????????????????????“MORE““MOREEQU““ASS““EQUAL““OR““OR““OR_ASS““CAR““CAR_ASS““AND““AND““AND_ASS““MOD“
????????????????????????????“MOD_ASS““ADD““SELF_ADD““ADD_ASS““SUB““SELF_SUB““SUB_ASS““ADRESS““DIV““DIV_ASS““MUL““MUL_ASS““NOR“
????????????????????????????“NOR_EQU““SIZEOF““轉(zhuǎn)義符““轉(zhuǎn)義符““轉(zhuǎn)義符““轉(zhuǎn)義符““轉(zhuǎn)義符““轉(zhuǎn)義符““轉(zhuǎn)義符““轉(zhuǎn)義符““轉(zhuǎn)義符““轉(zhuǎn)義符““轉(zhuǎn)義符““CONST_OCT““CONST_HEX““復(fù)合賦值運(yùn)算符<<=““復(fù)合賦值運(yùn)算符>>=“?};//單詞類型
????????string[]?keywords?=?{?“auto“?“break“?“case“?“char“?“const“?“continue“?“default“?“do“?“double“?“else“?“enum“?“extern“?
????????????????????????????????“float“?“for“?“goto“?“if“?“int“?“l(fā)ong“?“register“?“return“?“short“??“signed“?“sizoef“?
????????????????????????????????“static“?“struct“?“switch“?“typedef“?“union“?“unsigned“?“void“?“volatile“?“while“};//關(guān)鍵字
????????string[]?errortype?=?{?“數(shù)字表示錯(cuò)誤“?“未定義的字符“?“未知的轉(zhuǎn)義符號(hào)““字符串未關(guān)閉““字符不能為空““字符未關(guān)閉““字符長度錯(cuò)誤““注釋未關(guān)閉““超過注釋行數(shù)限制(520)“?};
????????int?index?=?0;//標(biāo)示符數(shù)組下標(biāo)
????????int?p?=?0;???//輸入指針
????????int?syn?=?0;?//分析結(jié)果
????????int?row?=?0;?//當(dāng)前行號(hào)
????????int?sum?=?0;?//計(jì)數(shù)常量
????????int?identifier?=?0;
????????int?error?=?0;//錯(cuò)誤代號(hào)
????????int?core?=?0;?//記錄標(biāo)示符內(nèi)存位置
????????System.Text.StringBuilder?stb;
????????string?str;
????????bool?flag;
????????SaveFileDialog?saveFileDialog1?=?new?SaveFileDialog();?//初始化文件保存對話框(以后彈出速度會(huì)更快)
????????OpenFileDialog?openFileDialog1?=?new?OpenFileDialog();
????????#endregion
????????public?Form1()
????????{
????????????InitializeComponent();??????
????????
????????????saveFileDialog1.FilterIndex?=?2;?
????????????saveFileDialog1.RestoreDirectory?=?true;
??????????
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件?????????926??2014-10-02?10:54??Lex_sunfiyes\Lex_sunfiyes.sln
?????文件???????38912??2015-02-08?14:59??Lex_sunfiyes\Lex_sunfiyes.v11.suo
?????目錄???????????0??2015-02-08?14:56??Lex_sunfiyes\Lex_sunfiyes\
?????文件?????????187??2014-10-02?10:54??Lex_sunfiyes\Lex_sunfiyes\App.config
?????目錄???????????0??2015-02-08?14:56??Lex_sunfiyes\Lex_sunfiyes\bin\
?????目錄???????????0??2015-02-08?14:56??Lex_sunfiyes\Lex_sunfiyes\bin\Debug\
?????文件????????1121??2014-10-06?10:23??Lex_sunfiyes\Lex_sunfiyes\bin\Debug\codeType.txt
?????文件???????22016??2014-08-31?15:36??Lex_sunfiyes\Lex_sunfiyes\bin\Debug\GlassButton.dll
?????文件??????403968??2014-10-08?18:02??Lex_sunfiyes\Lex_sunfiyes\bin\Debug\Lex_sunfiyes.exe
?????文件?????????187??2014-10-02?10:54??Lex_sunfiyes\Lex_sunfiyes\bin\Debug\Lex_sunfiyes.exe.config
?????文件???????54784??2014-10-08?18:02??Lex_sunfiyes\Lex_sunfiyes\bin\Debug\Lex_sunfiyes.pdb
?????文件???????22984??2015-02-08?14:57??Lex_sunfiyes\Lex_sunfiyes\bin\Debug\Lex_sunfiyes.vshost.exe
?????文件?????????187??2014-10-02?10:54??Lex_sunfiyes\Lex_sunfiyes\bin\Debug\Lex_sunfiyes.vshost.exe.config
?????文件?????????490??2010-03-17?22:39??Lex_sunfiyes\Lex_sunfiyes\bin\Debug\Lex_sunfiyes.vshost.exe.manifest
?????文件???????56038??2014-10-08?18:02??Lex_sunfiyes\Lex_sunfiyes\Form1.cs
?????文件???????23934??2014-10-08?17:22??Lex_sunfiyes\Lex_sunfiyes\Form1.Designer.cs
?????文件??????553689??2014-10-08?17:22??Lex_sunfiyes\Lex_sunfiyes\Form1.resx
?????文件????????4010??2014-10-02?15:42??Lex_sunfiyes\Lex_sunfiyes\Lex_sunfiyes.csproj
?????目錄???????????0??2015-02-08?14:56??Lex_sunfiyes\Lex_sunfiyes\obj\
?????目錄???????????0??2015-02-08?14:56??Lex_sunfiyes\Lex_sunfiyes\obj\Debug\
?????文件????????6297??2014-10-02?15:39??Lex_sunfiyes\Lex_sunfiyes\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件????????7094??2015-02-08?14:57??Lex_sunfiyes\Lex_sunfiyes\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????2229??2015-02-08?14:57??Lex_sunfiyes\Lex_sunfiyes\obj\Debug\Lex_sunfiyes.csproj.FileListAbsolute.txt
?????文件?????????975??2014-10-08?17:22??Lex_sunfiyes\Lex_sunfiyes\obj\Debug\Lex_sunfiyes.csproj.GenerateResource.Cache
?????文件????????7055??2014-10-02?15:42??Lex_sunfiyes\Lex_sunfiyes\obj\Debug\Lex_sunfiyes.csprojResolveAssemblyReference.cache
?????文件??????403968??2014-10-08?18:02??Lex_sunfiyes\Lex_sunfiyes\obj\Debug\Lex_sunfiyes.exe
?????文件??????364132??2014-10-08?17:22??Lex_sunfiyes\Lex_sunfiyes\obj\Debug\Lex_sunfiyes.Form1.resources
?????文件???????54784??2014-10-08?18:02??Lex_sunfiyes\Lex_sunfiyes\obj\Debug\Lex_sunfiyes.pdb
?????文件?????????180??2014-10-02?15:42??Lex_sunfiyes\Lex_sunfiyes\obj\Debug\Lex_sunfiyes.Properties.Resources.resources
?????文件???????????0??2014-10-02?10:54??Lex_sunfiyes\Lex_sunfiyes\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
?????文件???????????0??2014-10-02?10:54??Lex_sunfiyes\Lex_sunfiyes\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
............此處省略10個(gè)文件信息
評論
共有 條評論