• 大小: 338KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-08-17
  • 语言: C/C++
  • 标签: 译原理  哈工大  

资源简介

该词法分析器在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个文件信息

评论

共有 条评论