Coder Social home page Coder Social logo

lexical-analysis's Introduction

词法分析

目录结构

  • bin: 编译后的可执行文件
  • src: 源代码
  • example: 示例代码
  • lib: 依赖库及编译后的库
  • include: 头文件
  • test: 测试代码

设计

Regex

输入表达式,添加&符号,再转为后缀表达式

成员变量有三个:

  • raw_expr: 输入表达式
  • suffix_expr: 后缀表达式
  • expr: 添加&符号后的表达式

NFA

NFA由后缀表达式构造而来,跳转表用map<int, map<char, vector>>表示,其中第一个int表示状态,第二个char表示输入字符,vector表示跳转到的状态

DFA

DFA结构类似于NFA,跳转表用map<int, map<char, int>>表示,其中第一个int表示状态,第二个char表示输入字符,int表示跳转到的状态

Minimized DFA

最小化DFA,用于优化DFA,继承自DFA

说明

  • NFA、DFA、MinimizedDFA均有to_graph方法,用于生成Graphviz的dot文件,可以通过dot -Tpng -o output.png input.dot生成图片, graphviz在bin目录下
  • 对于NFA生成DFA方法,速度较慢,对于较大的NFA可能会有性能问题,初步分析为NFA状态较多,导致Closure闭包计算过多,其中存在大量重复计算,优化思路为采用时间复杂度为O(n)的方法,一次性计算所有节点的闭包,采用带备忘录的递归算法,即可达到化简计算的效果。

编译

mkdir build
cd build
cmake ..

运行

找到编译后的可执行文件,运行即可,直接运行bin下的可执行文件也可

lexical-analysis's People

Contributors

leezekee avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.