资源简介
该词法分析器在VS2012下开发(C#语言),实现了基本的C语言词法成分的分析功能,并且可以发现错误和指出错误类型,支持一件导入导出外部代码文件和词法分析结果,关键是界面美观~Ps(哈工大软件学院编译原理第一次实验)
代码片段和文件信息
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;//代码存放在字符数组中
char[] token = new char[256];//标示符数组
char[] trans = { ‘n‘‘r‘‘0‘‘t‘‘v‘‘b‘‘f‘‘a‘‘“‘‘\‘‘‘\\‘}; //11个转义字符表
char ch; //临时字符
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““转义符““转义符““转义符““转义符““转义符““转义符““转义符““转义符““转义符““转义符““转义符““CONST_OCT““CONST_HEX““复合赋值运算符<<=““复合赋值运算符>>=“ };//单词类型
string[] keywords = { “auto“ “break“ “case“ “char“ “const“ “continue“ “default“ “do“ “double“ “else“ “enum“ “extern“
“float“ “for“ “goto“ “if“ “int“ “long“ “register“ “return“ “short“ “signed“ “sizoef“
“static“ “struct“ “switch“ “typedef“ “union“ “unsigned“ “void“ “volatile“ “while“};//关键字
string[] errortype = { “数字表示错误“ “未定义的字符“ “未知的转义符号““字符串未关闭““字符不能为空““字符未关闭““字符长度错误““注释未关闭““超过注释行数限制(520)“ };
int index = 0;//标示符数组下标
int p = 0; //输入指针
int syn = 0; //分析结果
int row = 0; //当前行号
int sum = 0; //计数常量
int identifier = 0;
int error = 0;//错误代号
int core = 0; //记录标示符内存位置
System.Text.StringBuilder stb;
string str;
bool flag;
SaveFileDialog saveFileDialog1 = new SaveFileDialog(); //初始化文件保存对话框(以后弹出速度会更快)
OpenFileDialog openFileDialog1 = new OpenFileDialog();
#endregion
public Form1()
{
InitializeComponent();
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 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个文件信息
相关资源
- 编译原理C语言实现词法分析程序带容
- 编译原理的语义分析和中间代码生成
- 预测分析程序的实现
- 编译原理实验一词法分析 实验二语法
- 华中科技大学 编译原理 词法分析 实
- 简单的词法分析器
- 编译原理大作业完整的词法分析器
- 超强大的词法分析程序源代码C++版本
- 编译原理 算符优先分析法分析器的设
- 编译原理-语法分析器C语言源码
- C语言语法分析程序编译原理:LR
- 编译:语法分析程序报告源程序 c/c++
- 编译原理-语义分析
- SLR1文法分析程序(C++)
- 编译原理C0实验
- 编译原理 LL1语法分析器
- C语言 词法分析器 C#实现
- 编译原理语法分析器SLR(1)
- C语言编译器289297
- 编译原理 语法分析 语法树生成
- 词法分析器c++版
- 编译原理-词法分析与三地址代码生成
- C--Minus词法分析和语法分析设计.doc
- 编译原理词法分析含实验报告及源码
- Pascal文法子集的词法分析及递归下降
- 将算术表达式转换成四元式
- 构造预测分析表 编译原理 C语言版本
- 编译原理词法分析程序C语言编写
- LL1文法c语言实现
- c++实现词法分析器
评论
共有 条评论