• 根据java文法生成对应的词法分析器Content description


    资源下载地址:https://download.csdn.net/download/sheziqiong/86918774
    资源下载地址:https://download.csdn.net/download/sheziqiong/86918774

    根据java文法生成对应的词法分析器Content description

    使用java语言。

    包含标识符id,关键字keyword,数字num,运算符operator,分界符separator以及注释doc的辨别.

    包含空白字符的过滤。

    包含一些非法输入的处理和注释出错的处理。

    Input:stream of characters

    Output:sequence of tokens

    输入: i=2+1;

    输出如下:

    (id,i)
    (operator,=)
    (num,2)
    (operator,+)
    (num,1)
    (separator,;)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    Ideas/Methods

    Define some REs by yourself
    Convert REs into NFAs
    Merge these NFAs into a single NFA
    Convert the NFA into a DFAo with minimum states
    Programming based on the DFAo
    
    • 1
    • 2
    • 3
    • 4
    • 5

    Assumptions

    输入为一般的以Java语言写成的.java文件对应的字符流文本。

    不包含++,–,**,==二连运算符的判定。

    Related FA descriptions

    在这里插入图片描述

    Description of important Data Structures

    关键字,运算符,分界符的集合如下:

    在这里插入图片描述

    Description of core Algorithms

    FileIO类负责文件相关操作,包含读入输入字符流,清空输出文件,写入输出文件TypeCheck类负责识别token类型Analyzer类为核心类,继承了TypeCheck类,其中analyse()方法实现了词法分析,具体状态图参见,generate()方法将识别出的token格式化,打印并写回输出文件。

    Start类为普通启动类,创建Analyzer实例,调用analyse()方法进行词法分析。

    Use cases on running

    详见input.txt和output.txt

    启动器代码Start.java加入一条赋值语句作为一个输入case:

    package src;
    
    /**
     * @author Bourbon
     * @date 2017/10/26
     * @description 启动器
     */
    public class Start {
       public static void main(String[] args) {
           int i = 2+1;
          new Analyzer("./input.txt").analyse();
       }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    输出结果:

    Problems occurred and related solutions

    • Problem:

    无法将两种注释的情况处理编入一般的运算符之中。

    • Solution:

    将’/’运算符当作特殊字符单独处理。

    })

    
    ## Problems occurred and related solutions
    
    - Problem:
    
    
    无法将两种注释的情况处理编入一般的运算符之中。
    
    - Solution:
    
    
    将’/’运算符当作特殊字符单独处理。
    
    # 
    
    ```cpp
    在这里插入代码片
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    资源下载地址:https://download.csdn.net/download/sheziqiong/86918774
    资源下载地址:https://download.csdn.net/download/sheziqiong/86918774

  • 相关阅读:
    java框架-Spring-AOP
    ROS MarkerArray的几种常见用法
    记一次弱口令之后引发的获取服务器权限
    Linux应用编程概念
    深入探讨虚拟现实中的新型安全威胁:“盗梦攻击”及其防御策略
    AI数字人:最强声音驱动面部表情模型VideoReTalking
    EasyExcel导出自定义合并单元格文件
    公司大数据智能管理平台密码不正确 Hue平台进不去
    杰理之MIC 免电容方案需要设置【篇】
    牛顿迭代法
  • 原文地址:https://blog.csdn.net/newlw/article/details/127716721