Git Product home page Git Product logo

lexer's Introduction

Lexer

词法分析器(编译原理)

  • C计算机语言的编译程序的词法分析部分实现。 从左到右扫描每行该语言源程序的符号,拼成单词,换成统一的内部表示(token)送给语法分析程序。 为了简化程序的编写,有具体的要求如下: (1) 空白符仅仅是空格、回车符、制表符。 (2) 代码是自由格式。 (3) 注释应放在花括号之内,并且不允许嵌套
  • 标识符 (首符号为字母或下划线,其他由一个或更多的字母或数字或下划线构成)
  • 数 数字的属性包括三种:类型属性(整型、浮点型等)、进制属性(十进制、八进制、十六进制)和后缀属性(如短类型、宽类型等辅助类型信息) 如:123L
  • 字符常量 源程序中任意字符,除了’、backslash\、newline ‘a’
  • 字符串常量 源程序中任意字符,除了’、backslash\、newline “a”

功能:

  • (1) 按规则拼单词,并转换成二元式形式

  • (2) 删除注释行

  • (3) 删除空白符 (空格、回车符、制表符)

  • (4) 显示源程序,在每行的前面加上行号,并且打印出每行包含的记号的二元形式

  • (5) 发现并定位错误。

  • (1) 详细给出标识符、数字、字符和字符串的状态转换图

  • (2) 画出空白间隔符的状态转换图、换行符的状态装换图、注释(//、/* */)的状态转换图。

  • (3) 词法分析的具体功能实现是一个函数GetToken(),每次调用都对剩余的字符串分析得到一个单词或记号识别其种类,收集该记号的符号串属性,当识别一个单词完毕,采用返回值的形式返回符号的种类,同时采用程序变量的形式提供当前识别出记号的属性值。

  • (4) 标识符和保留字的词法构成相同,为了更好的实现,把语言的保留字建立一个表格存储,这样可以把保留字的识别放在标示符之后,用识别出的标示符对比该表格,如果存在该表格中则是保留字,否则是一般标识符。

lexer's People

Contributors

meishax avatar

Stargazers

 avatar  avatar

Watchers

James Cloos avatar  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.