


下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、The general format of Lex source is: Lex源的一般格式:definitions定义%rules规则%user subroutines 用户子程序where the definitions and the user subroutines are often omitted. The second % is optional, but the first is required to mark the beginning of the rules. The absolute minimum Lex program is thus 定义和用户子程序部分是通常省
2、略。第二个%是可选的,但首先是需要记录规则的开头。绝对最小的Lex程序是这样如此%(no definitions, no rules) which translates into a program which copies the input to the output unchanged. (没有定义,没有规则)转译成一个程序中把输入完全没有变化地复制到输出。In the outline of Lex programs shown above, the rules represent the users control decisions; they are a table, in whi
3、ch the left column contains regular expressions (see section 3) and the right column contains actions, program fragments to be executed when the expressions are recognized. Thus an individual rule might appear integer printf(found keyword INT);在上面显示的Lex程序里,规则代表用户控制的决定;在表中,左列包含正则表达式(见第三段)和右边栏包含动作,当表达
4、式被组织时程序片段将执行。因此独立的规则可能出现Integer printf(“发现的关键词 INT”);to look for the string integer in the input stream and print the message “found keyword INT” whenever it appears. In this example the host procedural language is C and the C library function printf is used to print the string. The end of the expre
5、ssion is indicated by the first blank or tab character. If the action is merely a single C expression, it can just be given on the right side of the line; if it is compound, or takes more than a line, it should be enclosed in braces. As a slightly more useful example, suppose it is desired to change
6、 a number of words from British to American spelling. Lex rules such as 为了寻找输入流中的字符串整数和输出信息“发现的关键词int”而不管它何时出现。在这个例子中,本地程序语言是C和C库函数函数printf是用来输出字符串。表达式的最后部分是用第一个空白处或制表符指出的。如果这种动作只不过是一个单一的C表达方式,它可能只出现在右侧;如果它是复合的,或着超过几行,它都必须加上注释。在一个稍微有用的例子,假设这是准备把英式拼法改成美式拼法。Lex规则如下:colour输出(“color”)mechanise输出(“mechan
7、ize”)petrol输出(“gas”)would be a start. These rules are not quite enough, since the word petroleum would become gaseum; a way of dealing with this will be described later. 将会是开端。这些规则是完全不够的,因为这个词petroleum会变成gaseum;处理这个问题的方法稍后会提到。Introduction 介绍YACC is short for Yet Another Compiler Compiler. A pun on t
8、he number of compiler, or parser, construction tools that were being created at the time. It is a tool that, given a BNF (Backus-Naur Form) style specification of a grammar, can generate a corresponding parser. It is worth noting that YACC will not accept every grammar presented to it. Far from it.
9、However the class of grammars that it does accept is generally powerful enough for most programming needs. YACC是Yet Another Comiler Compiler的缩写。/“编译器的数量,或者分析器,当时被创造的构造工具。这是一个工具,给定BNF(Backus-Naur形式)风格规格语法书,可以产生相应的解析器。值得注意的是,YACC不会接受所有的语法新事物。一点也不。然而这类文法它接受一般强大的足以让大多数编程的需要。很别扭一个关于编译器或分析器,和被同时创建的构建工具在数量
10、上的双关语。这是一个在已给定BNF(巴科斯诺尔范式)样式规格的语法情况下能生成相应的解析器的工具。值得一提的是,YACC的不一定能接受提供给它的每一个语法。远非如此。然而,它能接受的语法类一般也已强大到足以满足大多数的编程需求YACC was originally written by S. C. Johnson on a UNIX platform. It is closely tied in with Lex. A lexical analyser generating tool. Since then there have been many flavours of YACC imple
11、mented. Perhaps the most notable being BISON and BYACC. YACC最初是由S.C.Johnson在一个UNIX平台编写的,它与Lex密切相关。词汇分析仪生成工具。此后有许多被YACC执行的风格。最引人注目的也许是BISON、BYACC。YACC generates what are termed LR parsers. This means that they scan the input from left to right, the L bit, and produce a rightmost derivation from the b
12、ottom up, the R bit. LR parsers are also called bottom-up parsers. They are somewhat different to LL parsers. Similar to LR parsers these also scan the input from left to right, but this time construct a leftmost derivation instead. LL parsers are also called top down parsers. They have the distinct
13、 advantage that they can generally be implemented by hand. There are a number of techniques for doing this including predictive parsing and recursive descent parsing. There are now also a number of tools which can construct LL parsers automatically. Having said all this, it is generally a time consu
14、ming task to code a parser by hand, and an LR parser construction technique is inherently more powerful than an LL one. YACC产生LR分析器。这意味着他们从左至右扫描输入,在L位,并产生一个由下而上的最右推导,这是一点。LR分析器也被称为自底向上分析器。他们与LL分析器有稍微不同。类似于LR分析器的从左至右扫描输入,但这次构建的是最左推导。LL分析器也称为自顶向下分析器。他们有明显的优势,他们一般都可以手工实施。有很多这样的技术包括预测分析和递归下降分析程序。现在有许多工具
15、也能自动构建LL分析器。说到这里, 它通常是一个耗时手工给分析器编码的任务,并且一个LR分析器的构造技术自然比LL分析器更为强大。For both types of parser, either LR or LL, there is generally an extra piece of information which specifies how many lookahead tokens the parser uses to decide what action to perform. For instance an LR(1) parser uses one token of lookahead. This an important point because YACC generates a parser which uses one token of lookahead as well. That is the parser must decide, given the symb
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 冬季绿化养护与管理
- 宣传写作课件学习
- 宠物日常护理课件图片
- 二零二五年度新能源电池采购合同协议
- 2025版茶叶品牌重塑与市场拓展合同
- 二零二五年度个人消费贷款借款合同
- 二零二五年度测绘仪器采购与测绘项目验收服务合同
- 2025版跨国公司财务全球税务筹划合同
- 2025版高端医疗器械采购合同作废及供应商变更协议
- 二零二五年度阿拉尔经济技术开发区土地经营权流转合同
- 声环境质量自动监测系统质量保证及质量控制技术规范
- 2024年02月珠海市横琴粤澳深度合作区公安局2024年面向社会公开招考66名辅警笔试历年高频考点题库荟萃带答案解析
- 泡泡玛特营销案例分析
- 加工机械安全培训内容记录
- 对苯二甲酰氯的合成
- 大众进口途锐全车电路图01安装位置保险丝
- 酒店培训计划方案(通用8篇)
- 2023陕西延长石油集团矿业公司所属单位招聘666人笔试备考题库及答案解析
- 华北理工水质工程学教案09水的冷却-3冷却塔的热力计算基本方程、冷却塔的设计与计算
- 儿童手绘卡通word信纸贺卡背景模板
- 基业长青中国家族企业的东方智慧与长青之道
评论
0/150
提交评论