下载此文档

编译原理PPT教学课件-第3章_词法分析和词法分析程序.ppt


文档分类:IT计算机 | 页数:约57页 举报非法文档有奖
1/57
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/57 下载此文档
文档列表 文档介绍
编译原理
第三章
词法分析和词法分析程序
Principles piler Design
Chapter 3. Lexical Analysis
东华大学计算机学院
设计扫描器时应考虑的问题
词法分析程序亦称为扫描器
任务:扫描程序,识别单词
扫描器的输出是语法分析程序的输入
东华大学计算机学院
How to construct a lexical analyzer
A lexical analyzer is also called Scanner
The main task of the lexical analyzer is to read the input characters of the source program, and group them into lexemes.
The lexical analyzer outputs a sequence of tokens for each lexeme in the source program to the parser for syntax analysis.
东华大学计算机学院
词法分析的必要性
描述单词的结构比其它语法结构简单,仅用3型文法就够了;
将单词识别从语法分析识别分离出来,可采用更有效的工具实现;
有些语言的单词识别与前后文相关,不宜将其与语法分析合并;
使编译程序各部分独立出来,有利于设计、调试和维护
东华大学计算机学院
Lexical Analysis Versus Parsing
The separation of lexical and syntactic analysis often leads to a cleaner overall design.
Compiler efficiency is improved. A separate lexical analyzer allows us to apply specialized techniques that serve only the lexical task, not the job of parsing.
Compiler portability is enhanced. Input-device-specific peculiarities can be restricted to the lexical analyzer.
东华大学计算机学院
单词符号的内部表示
常用的内部表示方法: (class,value)
为便于阅读,常用助记符(或常量标识符、宏定义等)表示class。
单词的分类方法:可一词一类(+、-、begin、end等)或多词一类(如关键字类、操作符类、分隔符类、变量名类、常数类等)。
在识别出变量名、函数(过程)名时,还应进行查填符号表的工作。
东华大学计算机学院
Tokens
A token is a pair consisting of a token name and an optional attribute value (class,value)
The token name is an abstract symbol representing a kind of lexical unit, ., a particular keyword, or a sequence of input characters denoting an identifier.
The token names are the input symbols that the parser processes. We will often refer to a token by its token name.
东华大学计算机学院
识别标识符的若干约定和策略
一般来说,单词的长度是有限制的。
在允许长度下,应按最长匹配原则进行识别
有时需要超前扫描来进行单词识别。
在进行超前扫描时,还应注意“回退”字符,即将多吃掉的字符退还回输入缓冲区。
东华大学计算机学院
Token Recognition
All tokens have finite length.
Tokens are recognized when all possible symbols are scanned.
Sometimes we need to look at least one additional character ahead.

编译原理PPT教学课件-第3章_词法分析和词法分析程序 来自淘豆网m.daumloan.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数57
  • 收藏数0 收藏
  • 顶次数0
  • 上传人3346389411
  • 文件大小0 KB
  • 时间2012-05-07