GNU Bison 中文手册
GNU Bison 中文手册
20050620 GNU Bison 中文手册翻译完成
GNU Bison实际上是使用最广泛的Yacc-like分析器生成器,使用它可以生成解释器,编译器,协议实现等多种程序. 它不但与Yacc兼容还具有许多Yacc不具备的特性.
这个手册编写十分完整,带你领略Bison在使用中的各个细节(注:并不是实现细节).
如果发现错误,语句不通顺,意思不明,确请立即发邮件把您的建议或者您认为正确的翻译 写信告诉我,非常需要并感谢你的帮助!
英文原件页面
这个翻译版手册也是在GNU Free Documentation License下发布.
提供以下格式:(会陆续增加格式)
原始texinfo格式(78,999字节,gzip压缩)
HTML格式(111,882字节,gzip压缩)
HTML格式(109,570字节,zip压缩)
HTML格式使用一个由我patch的texi2html生成,如果需要的话可以跟我联系.
一些参考:
GNU Bison Project
The LEX & YACC Page
GNU Flex Project
Yacc: 另一个编译器的编译器Stephen C. Johnson著,寒蝉退 士译
--------------------------------------------------------------------------------
[顶层] [内容] [索引] [ ? ]
Bison
这个手册是针对GNU Bison (版本2.0,22 December 2004), GNU分析器生成器.
Copyright © 1988, 1989, 1990, 1991, 1992, 1993, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
Chinese(zh_CN) translation:Xiao Wang
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover texts being "A GNU Manual," and with the Back-Cover Texts as in (a) below. A copy of the license is included in the section entitled "GNU Free Documentation License."
(a) The FSF's Back-Cover Text is: "You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development."
Bison简介-Introduction
使用Bison的条件-Conditions for Using Bison
GNU GENERAL PUBLIC LICENSE GNU General Public License 说明了你如何使用和共享Bison
教学章节:
1. 和Bison相关的一些基本概念-The Concepts of Bison 理解Bison的基本概念.
2. 实例-Examples 三个详细解释的使用Binson的例子.
参考章节:
3. Biosn的语法文件-Bison Grammar Files 编写Bison声明和规则.
4. 分析器C语言接口-Parser C-Language Interface 分析器函数yyparse的C语言接口.
5. Bison分析器算法-The Bison Parser Algorithm Bison分析器运行时如何工作.
6. 错误恢复-Error Recovery 编写错误恢复规则.
7. 处理上下文依赖-Handling Context Dependencies 如果你的语言的语法过于凌乱以至于Bison不能直接处理,你该怎么做.
8. 调式你的分析器-Debugging Your Parser 理解或调试Bison分析器.
9. 调用Bison-Invoking Bison 如何运行Bison(来生成分析源文件).
A. Bison符号-Bison Symbols 解释所有Bison语言的关键字.
B. 词汇表-Glossary 解释基本概念.
10. 常见问题-Frequently Asked Questions 常见问题
C. 复制这个手册-Copying This Manual 复制这个手册的许可
索引-Index 文本交叉索引
--- 详细节点列表 ---
Bison的基本概念-The Concepts of Bison
1 语言与上下文无关文法-Languages and Context-Free Grammars 从数学的概念来介绍语言和上下文无关文法.
1.2 从正规文法转换到Bison的输入-From Formal Rules to Bison Input 怎样用Bison的语法表示各种文法.
1.3 语义值-Semantic Values 每个记号或者语法组可有一个语义值(例如:整数的数值,标识符的名称等等)
1.4 语义动作 每个规则可有一个包含C代码的动作
1.5 编写GLR分析器-Writing GLR Parsers 为普通的上下文无关文法编写分析器
1.6 位置-Locations 追踪位置
1.7 Bison的输出:分析器文件-Bison Output: the Parser File Bison的输入和输出是什么,怎样使用Bison的输出
1.8 使用Bison的流程-Stages in Using Bison 编写和运行Bison语法分析程序的流程.
1.9 Bison语法文件的整体布局-The Overall Layout of a Bison Grammar Bison语法文件的整体布局
编写GLR分析器-Writing GLR Parsers
5.1 使用GLR分析器分析非歧义文法
1.5.2 使用GLR解决歧义-Using GLR to Resolve Ambiguities 使用GLR分析器解决歧义
1.5.3 编译GLR分析器时需要考虑的问题-Considerations when Compiling GLR Parsers GLR分析器需要一个现代的C编译器
实例-Examples
1 逆波兰记号计算器-Reverse Polish Notation Calculator 逆波兰记号计算器,我们的第一个例子,并不带有操作符优先级
2.2 中缀符号计算器:calc-Infix Notation Calculator: calc 中缀代数符号计算器,简单地介绍操作符优先级.
2.3 简单的错误恢复-Simple Error Recovery 在出现语法错误后继续分析
2.4 带有位置追踪的计算器:ltcalc-Location Tracking Calculator: ltcalc 展示@n和@$的用法
2.5 多功能计算器:mfcalc-Multi-Function Calculator: mfcalc 带有存储和触发功能的计算器.它使用了多种数据类型来表示语义值.
2.6 练习-Exercises 一些改进多功能计算器的方案
逆波兰记号计算器-Reverse Polish Notation Calculator
1.1 rpclac的声明部分-Declarations for rpcalc rpclac的Prologue(声明)部分.
2.1.2 rpcalc的语法规则-Grammar Rules for rpcalc 带注释的rpcalc语法规则
2.1.3 rpcalc的词法分析器-The rpcalc Lexical Analyzer 词法分析器
2.1.4 控制函数-The Controlling Function 控制函数
2.1.5 错误报告的规则-The Error Reporting Routine 错误报告的规则
2.1.6 运行Bison来产生分析器-Running Bison to Make the Parser 使用Bison生成分析器
2.1.7 编译分析器文件-Compiling the Parser File 使用C编译器编译得到最终结果
rpcalc的语法规则-Grammar Rules for rpcalc
1.2.1 解释input-Explanation of input
2.1.2.2 解释line-Explanation of line
2.1.2.3 解释expr-Explanation of expr
位置追踪计算器:ltcalc-Location Tracking Calculator: ltcalc
4.1 ltcalc的Declarations-Declarations for ltcalc ltcalc的Bison和C语言的声明
2.4.2 ltcalc的语法规则-Grammar Rules for ltcalc 详细解释ltcalc的语法规则
2.4.3 ltcalc的词法分析器-The ltcalc Lexical Analyzer. 词法分析器
多功能计算器:mfcalc-Multi-Function Calculator: mfcalc
5.1 mfcalc的声明-Declarations for mfcalc 多功能计算器的Bison声明
2.5.2 mfcalc的语法规则-Grammar Rules for mfcalc 计算器的语法声明
2.5.3 mfcalc的符号表-The mfcalc Symbol Table 符号表管理规则
Bison语法文件-Bison Grammar Files
1 Bison语法的提纲-Outline of a Bison Grammar 语法文件的整体布局
3.2 符号,终结符和非终结符-Symbols, Terminal and Nonterminal 终结符与非终结符
3.3 描述语法规则的语法-Syntax of Grammar Rules 如何编写语法规则
3.4 递归规则-Recursive Rules 编写递归规则
3.5 定义语言的语义-Defining Language Semantics 语义值和动作
3.6 追踪位置-Tracking Locations 位置和动作
3.7 Bison声明-Bison Declarations 所有种类的Bison声明在这里讨论
3.8 在同一个程序中使用多个分析器-Multiple Parsers in the Same Program 将多个Bison分析器放在一个程序中
Bison语法提纲-Outline of a Bison Grammar
1.1 Prologue部分-The prologue Prologue部分的语法和使用
3.1.2 Bison Declarations部分-The Bison Declarations Section Bison declarations部分的语法和使用
3.1.3 语法规则部分-The Grammar Rules Section Grammar Rules部分的语法和使用
3.1.4 Epilogue部分-The epilogue Epilogue部分的语法和使用
定义语言的语义-Defining Language Semantics
5.1 语义值的数据类型-Data Types of Semantic Values 为所有的语义值指定一个类型.
3.5.2 多种值类型-More Than One Value Type 指定多种可选的数据类型.
3.5.3 动作-Actions 动作是一个语法规则的语义定义.
3.5.4 动作中值的数据类型-Data Types of Values in Actions 为动作指定一个要操作的数据类型.
3.5.5 规则中的动作-Actions in Mid-Rule 多数动作在规则之后, 这一节讲述什么时候以及为什么要使用规则中间动作的特例.
追踪位置-Tracking Locations
6.1 位置的数据类型-Data Type of Locations 描述位置的数据类型.
3.6.2 动作和位置-Actions and Locations 在动作中使用位置.
3.6.3 位置的默认动作-Default Action for Locations 定义了一个计算位置的通用方法.
Bison声明-Bison Declarations
7.1 符号类型名称-Token Type Names 声明终结符
3.7.2 操作符优先级-Operator Precedence 声明终结符的优先级和结合性
3.7.3 值类型集-The Collection of Value Types 声明一组语义值类型
3.7.4 非终结符-Nonterminal Symbols 声明非终结语义值的类型
3.7.5 在分析执行前执行一些动作-Performing Actions before Parsing 在分析开始前执行的代码
3.7.6 释放被丢弃的符号-Freeing Discarded Symbols 声明如何释放符号
3.7.7 消除冲突警告-Suppressing Conflict Warnings 消除分析冲突时的警告
3.7.8 开始符号-The Start-Symbol 指明开始符号
3.7.9 纯(可重入)分析器-A Pure (Reentrant) Parser 请求一个可重入的分析器
3.7.10 Bison声明总结-Bison Declaration Summary 一个所有Bison声明的总结
分析器C语言接口-Parser C-Language Interface
;4.1 分析器函数yyparse-The Parser Function yyparse 如何调用yyparse以及它的返回值.
4.2 词法分析器函数yylex-The Lexical Analyzer Function yylex 你必提供一个读入记号的函数yylex.
4.3 错误报告函数yyerror-The Error Reporting Function yyerror 你必须提供一个函数yyerror.
4.4 在动作中使用的特殊特征-Special Features for Use in Actions 在动作中使用的特殊特征.
词法分析器函数yylex-The Lexical Analyzer Function yylex
2.1 yylex的调用惯例-Calling Convention for yylex yyparse如何调用yylex.
4.2.2 记号的语义值-Semantic Values of Tokens yylex是如何返回它已经读入的记号的语义值.
4.2.3 记号的文字位置-Textual Locations of Tokens 如果动作需要,yylex是如何返回记号的文字位置(行号,等等).
4.2.4 纯分析器的调用惯例-Conventions for Pure Parsers 调用惯例如何区分一个纯分析器 (参阅一个纯(可重入)分析器-A Pure (Reentrant) Parser一章).
Bison分析器算法-The Bison Parser Algorithm
1 超前扫描记号-Look-Ahead Tokens 当分析器决定做什么的时候它查看的一个记号.
5.2 移进/归约冲突-Shift/Reduce Conflicts 冲突:移进和归约均有效.
5.3 操作符优先级-Operator Precedence 由于解决冲突的操作符优先级.
5.4 上下文依赖优先级-Context-Dependent Precedence 当一个操作符的优先级依赖上下文.
5.5 分析器状态-Parser States 分析器是一个带有栈的有限状态机.
5.6 归约/归约冲突-Reduce/Reduce Conflicts 在同意情况下可以应用两个规则.
5.7 神秘的归约/归约冲突-Mysterious Reduce/Reduce Conflicts 看起来不平等的归约/归约冲突.
5.8 通用LR (GLR)分析-Generalized LR (GLR) Parsing 分析arbitrary上下文无关文法.
5.9 栈溢出以及如何避免它-Stack Overflow, and How to Avoid It 当栈溢出时发生的事情以及如何避免它.
操作符优先级-Operator Precedence
3.1 什么时候需要优先级-When Precedence is Needed 一个展示为什么需要优先级的例子
5.3.2 指定操作符的优先级-Specifying Operator Precedence 在Bison的语法中如何指定优先级
5.3.3 优先级使用的例子-Precedence Examples 这些特性在前面的例子中是怎样使用的
5.3.4 优先级如何工作-How Precedence Works 它们如何工作
处理上下文依赖-Handling Context Dependencies
1 符号类型中的语义信息-Semantic Info in Token Types 对记号的分析可能依赖于语义上下文.
7.2 词法关联-Lexical Tie-ins 对记号的分析可能依赖上下文.
7.3 词法关联和错误恢复-Lexical Tie-ins and Error Recovery 词法关联含有如何编写错误恢复规则的暗示.
调试你的分析器-Debugging Your Parser
1 理解你的分析器-Understanding Your Parser 理解你的分析器的结构
8.2 跟踪你的分析器-Tracing Your Parser 跟踪你的分析器的执行
调用Bison-Invoking Bison
1 Bison选项-Bison Options 按简写选项的字母顺序详细描述所有选项
9.2 选项交叉键-Option Cross Key 按字母顺序列出长选项
9.3 Yacc库-Yacc Library 与Yacc兼容的yylex和main
常见问题-Frequently Asked Questions
1 分析器栈溢出-Parser Stack Overflow 突破栈限制
10.2 我如何复位分析器-How Can I Reset the Parser yyparse保持一些状态
10.3 被销毁的字符串-Strings are Destroyed yylval丢掉了字符串的追踪
10.4 C++分析器-C++ Parsers 使用C++编译器编译分析器
10.5 实现跳转/循环-Implementing Gotos/Loops 在计算器中控制流
复制这个文档-Copying This Manual
C.1 GNU Free Documentation License 复制这个手册的许可.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
Bison简介-Introduction
Bison是一种通用目的的分析器生成器. 它将LALR(1)上下文无关文法的描述转化成分析该文法的C程序. 一旦你精通Bison, 你可以用它生成从简单的桌面计算器到复杂的程序设计语言等等许多语言的分析器.
Bison向上兼容Yacc:所有书写正确的Yacc语法都应该可以不加更改地与Bison一起工作. 熟悉Yacc的人能毫不费力地使用Bison. 你应该熟练地掌握C程序设计语言,这样你才能使用Bison和理解这个手册.
我们会在这个教程的最初几章解释BIson的基本概念,并且展示三个详细解释的例子, 这些例子将在教程的最后被构建. 如果你对Bison或者Yacc一无所知, 你应该首先阅读这些章节. 接下来的参阅章节详细地阐述了Bison的各个方面.
Bison主要由Rovert Corbett编写.Richard Stallman使它与Yacc兼容. Carnegie Mellon大学的Wilfred Hansen为Bison添加了多字符字符串文字(multi-character string literals)和其它一些特性.
这个版本的手则主要与Bison2.0相一致.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
使用Bison的条件-Conditions for Using Bison
为了允许非自由程序(nonfree programs)使用Bison生成的LALR分析器C代码, 我们在Bison版本1.24的时已经修改了yyparse的发布条款(distribution terms for yyparse). 在这之前,这些分析器只能用于自由软件(free software)的程序.
其它GNU编程工具,例如GNU C编译器从未有过类似的要求. 它们总能用于非自由软件的发布. Bison与它们不同的原因并不是出于特殊策略的决定, 而是由于应用通用许可证(General Public License)到所有的Bison源代码造成的结果.
Bison工具的输出-也就是Bison分析器文件(the Bison parser file)包括大小不固定的Bison代码片段. 这些代码片段来源于yyparse函数.(你的语法的动作被Bison插入到这个函数的某个位置, 但是函数的其余部分并未更改).当我们应用GPL条款到yyparse的代码的时候, 它产生的效果就是Bison的输出只能到自由软件.
我们并未更改条款使出于对那些希望是软件私有化的人的同情. 所有的软件都应该是自由软件.但是我们的结论是: 使Bison只能用于自由软件,这对鼓励人们使其它软件变为自由软件作用甚微. 所以我们决定将使用Bison的条件与使用其它GNU工具的条件相一致. (注:即和GCC一样可以用于非自由软件).
这个特例仅仅在Bison生成LALR(1)分析器的C代码时适用. 否则,GPL条款仍然正常的执行. 你可以通过查看代码,看其是否由这样的说明"As a special execption, when this file is copied by Bison into a Bison output file, you may use that output file without restriction."来分辩这个特例是否适用于你的`.c'输出文件.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright © 1989, 1991 Free Software Foundation, Inc.
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
Preamble
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and modification follow.
This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
one line to give the program's name and a brief idea of what it does.
Copyright (C) yyyy name of author
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type show w'. This is free software, and you are welcome to redistribute it under certain conditions; type show c' for details.
The hypothetical commands show w' and show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than show w' and show c'; they could even be mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
signature of Ty Coon, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
1. 和Bison相关的一些基本概念-The Concepts of Bison
这一章介绍了许多基本概念,但没有提及一些感觉不到的细节. 如果你并不了解如何使用Bison/Yacc,我们建议你仔细阅读这一章.
1 语言与上下文无关文法-Languages and Context-Free Grammars 从数学的概念来介绍语言和上下文无关文法.
1.2 从正规文法转换到Bison的输入-From Formal Rules to Bison Input 怎样用Bison的语法表示各种文法.
1.3 语义值-Semantic Values 每个记号或者语法组可有一个语义值(例如:整数的数值,标识符的名称等等)
1.4 语义动作 每个规则可有一个包含C代码的动作
1.5 编写GLR分析器-Writing GLR Parsers 为普通的上下文无关文法编写分析器
1.6 位置-Locations 追踪位置
1.7 Bison的输出:分析器文件-Bison Output: the Parser File Bison的输入和输出是什么,怎样使用Bison的输出
1.8 使用Bison的流程-Stages in Using Bison 编写和运行Bison语法分析程序的流程.
1.9 Bison语法文件的整体布局-The Overall Layout of a Bison Grammar Bison语法文件的整体布局
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
1 语言与上下文无关文法-Languages and Context-Free Grammars
为了使Bison能分析语言,这种语言必须由上下文无关文法(context-free grammar)描述. 也就是说,你必须指出一个或者多个语法组(syntactic groupings)以及从语法组的部分构它的建整体的规则. 例如,在C语言中,有一种我们称之为`表达式(expression)'的语法组. 一个生成表达式的规则可能是"一个表达式由一个减号和另一个表达式构成". 另外一个规则可能是"一个表达式可以是一个整数". 就象你看到的一样,规则经常是递归定义的,但是必须有一个结束递归的规则.
用于表示这些规则的最普遍的系统是Backus-Naur 范式(Backus-Naur Form)或者"BNF". 发明这种语言的目的是用来阐述Algol 60. 任何用BNF表示的文法都是一种上下文无关文法. Bison要求它的的输入必须用BNF表示.
上下文无关文法有许多重要的子集.尽管Bison可以处理几乎所有的上下文无关文法, 但Bison针对LALR(1) 文法(LALR(1) grammars)做了优化. 简而言之,在这些文法中(注:指LALR(1)),我们可以告之如何分析仅代有一个超前扫描记号的输入字符串的任意部分. 严格的说,这是一个LR(1)文法的描述. LALR(1)包括了与多难以分析的额外限制. 幸运的是,在实际中,我们很难找到一个是LR(1)文法而不是LALR(1)文法的例子. 参阅神秘的归约/归约冲突-Mysterious Reduce/Reduce Conflicts,以获取更多信息.
LALR(1)文法分析器具有确定性(deterministic), 这就意味着应用于输入的下一个文法规则取决于之前的输入和确定的部分剩余输入(我们称之为一个超前扫描记号(look-ahead). 一个上下文无关文法可能是有歧义的(ambiguous),即可能可以应用多种规则来获取某些输入. 即使非歧义性文法也可能使不确定(non-deterministic)的, 即没有总能足以决定下一个应用的文法规则的确定的超前扫描记号。使用孰知的GLR技术,Bison的GLR就可以分析这些更为普通的上下文无关文法. 当任意给定字符串的可能的分析是确定的情况下,Bison可以处理任意上下文无关文法.
在正式的语言语法规则中,每一种语法单元或组合被称之为符号(symbol). 那些可以通过语法规则被分解成更小的结构的符号叫做非终结符(nonterminal symbols). 那些不能被再分的符号叫做终结符(terminal symbols)或者记号类型(token types). 我们把同终结符相对应的输入片段叫做记号(token), 把同单个非终结符相对应的输入片段叫做组(grouping).
我们可以使用C语言做为例子来解释什么是符号,以及终结符和非终结符的含义. C语言的记号包括标识符,常量(数字或者字符串)以及各种关键字,数学操作符和标点符号. 所以C语言语法的终结符包括identifier',number',string',加上每个关键字的符号,操作符或者标点符号. 例如:if',return',const',static',int',char',plus-sign',open-brace',close-brace',`comma'以及更多. (这些记号可以再分为字符,但是这些是词法学而不是语法学的事情)
这是一个如何将C函数分解成记号的例子:
int /* 关键字 int' */ square (int x) /* identifier, open-paren, 关键字 int', identifier, close-paren /
{ / open-brace /
return x * x; / 关键字 `return', identifier, asterisk, identifier, semicolon /
} / close-brace */
C语言的语法组包括表达式,语句,声明和函数定义. 这些由C语言语法中的非终结符expression',statement',declaration'和funcation definition'表示. 完整的语法还使用了许多额外的语言结构,每种结构都有自己的非终结符来表示上述四种的含义. 上面的例子是一个函数的定义,它包括了一个声明和一个语句. 每一个x'一个表达式,而且x * X'也是一个表达式.
每一个非终结符必须有一个描述如何由更简单结构组成这个非终结符的语法规则. 例如,一种C的语句是return语句的非正式表达将由如下的语法规则描述:
一种语句可以由一个return'关键字,一个expression'何以个`semicolon'组成.
还有许多其它对应`statement'的规则,每一种规则对应一种C语句.
我们必须注意到一种特殊的非终结符,这种非终结符定义了语言的一个完整表述. 我们称之为开始符号(start symbol). 在编译器中,这意味着一个完整的输入程序. 在C语言中,非终结符`sequence of definitions and declarations'扮演了这个角色.
例如,1+2'是以个有效的C表达式--一个有效的C程序的部分--但它不能做为一个C程序的全部(entire). 在C语言的上下文无关文法中,这遵循了expression'不是开始符号的事实.
Bison分析器读取一个记号序列做为它的输入并使用语法规则将记号组合. 如果输入是有效的,最终的结果是将整个的输入序列分析整理到开始符号. 如果我们使用C语言的语法,整个的输入必须是一个`sequence of definitions and declarations', 否则分析器会报告一个语法错误.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
2 从正规文法转换到Bison的输入-From Formal Rules to Bison Input
正规文法是一种数学结构.为了定义Bison要分析的语言, 你必须用Bison语法编写一个表达该语言的文件,即一个Bison 语法(Bison grammar)文件. 参阅 Bison的语法文件-Bison Grammar Files.
就象C语言中的标识符一样,在Bison的输入中,一个正规文法的非终结符由一个标识符表示. 根据惯例,非终结符应该用小写子母表示,例如expr,stmt或者declaration.
在Bison中,终结符也被称为符号类型(token type). 符号类型也可以由类似C语言标识符来表示. 根据惯例,这些标识符因改用大写子母表示以区分它和非终结符. 例如,INTEGER,INDENTIFIER,IF或者RETURN. 一个表示某语言的特定关键字的终结符应该由紧随该关键字之后的它的大写表示来命名. 终结符error保留用作错误恢复之用. 参阅 符号-Symbols.
一个终结符也可以由一个像C中的字符常量一样的一个字符来表示. 当一个记号就是一个字符(括号,加号等等)的时候,你可以这样做: 使用同一个字符做为那个记号的终结符.
第三种表示终结符的方法是使用包含一些字符的C字符串常量. 获取更多这方面的信息可以参阅 符号-Symbols.
语法规则在Bison语法中也有相应的表示.例如,下面有一个C语言return语句的规则. 在引号中的分号,是一个字符记号,它是用来表示C语言部分语法的. 没有在引号中的分号和冒号是Bison用来表示每一条规则的标点符号.
stmt: RETURN expr ';'
;
获取这方面更多信息,参阅 语法规则的语法-Syntax of Grammar Rules.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
3 语义值-Semantic Values
正规文法仅仅靠类别来选择记号:例如,如果一个规则提到了终结符integer constant', 这就意味着任何整数常量在那个位置上都是语法有效的. 常量的精确值与如何分析输入不相关:如果x+4'符合语法,那么x+1'或者x+3989'也符合语法.
但是,当分析输入时,它的精确值是非常重要的,通过精确值可以了解输入的含义. 如果一个编译器不能区别程序中的4,1和3989等常量,毫无疑问,这个编译器是没有用的! 因此,每一个Bison语法的记号既含有一个符号类别也有一个语义值(semantic value). 获取这方面的更多信息,参阅 定义语言的语义-Defining Language Semantics.
符号类型是在语法中定义的终结符,例如INTEGER,IDENTIFIRE或者','. 它告诉你决定记号可能有效出现的位置以及如何将它组合成其它记号的信息. 语法规则只知道符号的类型,其它的什么都不知道.
语义值包括了记号的所有剩余信息.例如整数的数值,标识符的名称. (一个如','的记号只是一个标点,并不需要语义值.)
例如,一个分类为INTEGER的记号包含语义值4. 另一个也被分类为INTEGER的记号的语义值却是3989. 当一个语法规则表明INTEGER是允许的,任意的这些记号都是可接受的,因为它们都是INTEGER. 当一个分析器接受了记号,它会跟踪这个记号的语义值.
每一个语法组和它的非终结符也可已有语义值. 一个很典型的例子,在计算器中,一个表达式含有一个数值做为它的语义值, 在程序语言编译器中.一个典型的表达式含有一个用于描述它含义的树型结构做为语义值.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
4 语义动作
为了更加实用,一个程序不仅仅要分析输入而且必须做的更多. 它应该可以在输入的基础上产生一些输出. 在Bison语法中,一个语法规则可以有一个包括多个C语句的动作(action). 分析器每次识别一个规则的匹配,相应的动作就会被执行. 获取这方面的更多信息,参阅 动作-Actions.
大多数时候,动作的目的是从部分结构的语义值计算整个结构的语义值. 例如,加入我们有一个规则表明一个表达式可以由两个表达式相加而成. 当分析器识别了一个加法和,每一个子表达式都有一个描述其如何构建的语义值. 这个规的动做就是为了新识别的大表达式建立一个类似的语义值.
例如,这里的一个规则表明一个表达式可由两个表达式相加而成.
expr: expr '+' expr { 赋值. 这样做的结果就是与line相关联的语义值并未被初始化(它的值是不可预期的). 如果那个值被使用的话,这会成为一个bug,但是我们并未使用它. rpcalc一旦已经打印了用户输入行的值,就不再需要那个值了.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
1.2.3 解释expr-Explanation of expr
exp组有很多规则,每一个都是一种表达式. 第一个规则处理最简单的表达式:仅仅是数字的表达式. 第二个处理看起来像两个表达式后紧跟一个假发符号的加法表达式. 第三个处理减法等等.
exp: NUM
| exp exp '+' {
= 1 + 2; } | exp exp '-' {
= 1 - 2; }
…
;
我们已经使用`|'将exp的规则连接起来. 但是我们也可以将它们分开来写:
exp: NUM ;
exp: exp exp '+' {
= 1 + 2; } ; exp: exp exp '-' {
= 1 - 2; } ;
…
大部分规则都有从其部分值来计算表达式值的动作. 例如,在加法的规则中,1指的是第一个部件exp, 而2指的是第二个部件. 第三个部件'+'并没有相关联的语义值. 但是如果它有语义值的话,你可以用$3来代表. 当yyparse使用这个规则识别了一个加法和表达式, 两个自表达式值的相加而得到了整个表达是的值. 参阅 动作-Actions.
你不必为每一个规则都指定动作. 当一个规则没有动作时,Bison会默认地将1的值复制给以便成为刚刚被规则识别的加法表达式的语义值. 如果`+'记号有一个有用的语义值,可以通过2引用它.
注意到垂直杠字符|'的确是一个分隔符, 并且动作只被附加到一个单一的规则上. 这是一点和Flex工具不同的地方. 在Flex中,|'既代表"或者"也能代表"与下一个规则有着相同的动作". 在下面的例子中,动作仅在`b'被发现的时候触发.
a-or-b: 'a'|'b' { a_or_b_found = 1; };
如果你并没有指明一个规则的动作,Bison提供了默认的动作: 和$n结构总是那种类型.
如果你已经使用了%union指定了多种数据类型, 那么你必须从这些类型中为每一个可以有语义值的终结符或非终结符声明一种. 之后当你每次使用复制来设置它的值, 并且规则之中的后一个动作可应使用n引用这个值. 由于没有符号可以命名这个动作, 所以没有办法为这个值事先声明一个数据类型. 每当你引用这个值的时候你必须使用`<…>n'结构来指明一个数据类型.
没有办法在规则中动作中为整个规则设定一个值, 因为对=6;) 之后,前一个动作的语义值(注
由于分析器为了执行动作而进行强制分析, 在一个规则没有完全被识别之前执行动作经常会导致冲突. 例如,如下的两个规则,并没有规则中的动作,可以在分析器中共存. 因为分析器可以移进一个左大括号并且查看之后跟随的符号来确定这是否是一个声明.
compound: '{' declarations statements '}'
| '{' statements '}'
;
但是当我们向下面这样添加一个规则中的动作时,规则就失效了:
compound: { prepare_for_local_variables (); }
'{' declarations statements '}'
| '{' statements '}'
;
现在,当分析器还没有读到左到括号的时候,它就被迫决定是否执行规则中的动作. 换句话说,当分析器没有足够的信息作出正确选择的时候, 它就会强制使用一个或者其它的规则. (这个时候由于分析器仍在决定怎么办, 左大括号记号被称之为超前扫描记号(look-ahead). 参阅 超前扫描记号-Look-Ahead Token.) (注:这个时候两个规则的超前扫描记号都是`{')
你可能认为给这两个规则放置相同的动作可以解决这个问题,就像这样:
compound: { prepare_for_local_variables (); }
'{' declarations statements '}'
| { prepare_for_local_variables (); }
'{' statements '}'
;
但是这种方法不可行,因为Bison并没有意识到两个动作是完全相同的. (Bison永远不会尝试理解动作中的C代码.)
如果语法是这样的:可以依靠第一个记号(C语言就是这样)识别出一个声明. 那么将动作放到左大括号后是一个可行的解决方法. 就像这样:
compound: '{' { prepare_for_local_variables (); }
declarations statements '}'
| '{' statements '}'
;
现在接下来的声明或者语句的第一个记号(注:超前扫描记号) 在任何情况下都会告知Bison该使用哪一个规则.
另外一种解决方法是将动作放入一个做为子规则的非终结符.
subroutine: /* empty */
{ prepare_for_local_variables (); }
;
compound: subroutine
'{' declarations statements '}'
| subroutine
'{' statements '}'
;
现在Bison不用却确定最终使用的规则就可执行规则subroutine中的动作. 注意到:现在动作已经在规则的结尾. 任何规则中间的动作都可以由这种方法转化为一个规则结尾的动作, 并且这也是Bison处理规则中间的动作的方法.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
6 追踪位置-Tracking Locations
虽然语法规则和语义值对于编写功能完善的分析器来说足够用了, 但是处理一些额外的信息特别是符号位置的信息也是非常有用的.
处理位置的方法由一个数据类型和规则被匹配时执行的动作定义的.
6.1 位置的数据类型-Data Type of Locations 描述位置的数据类型.
3.6.2 动作和位置-Actions and Locations 在动作中使用位置.
3.6.3 位置的默认动作-Default Action for Locations 定义了一个计算位置的通用方法.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
6.1 位置的数据类型-Data Type of Locations
由于所有的记号和组总是使用相同的类型, 定义一个位置的数据类型要比定义语义值的简单的多.
位置的类型由一个名为YYLTYPE的宏定义. 当YYLTYPE没有被定义的时候, Bison使用含有四个成员的结构体作为默认的定义:
typedef struct YYLTYPE
{
int first_line; /* 第一行 /
int first_column; / 第一列 /
int last_line; / 最后一行 /
int last_column; / 最后一列 */
} YYLTYPE;
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
6.2 动作和位置-Actions and Locations
动作不仅仅是为了定义语言的语义, 它还可以使用位置描述输出的分析器的行为.
最明显的为语法组建立位置的方法与计算语义值的方法相似. 在一个给定的规则中, 多种结构可以用于访问被匹配元素的位置. 右手端第n个部件的位置是@n 而左边的组的位置是@$.
这是一个基本的使用位置的默认数据类型的例子:
exp: …
| exp '/' exp
{
@.first_column = @1.first_column;
@.first_line = @1.first_line;
@.last_column = @3.last_column;ip
@.last_line = @3.last_line;
if ($3)
= 1 / 3; else {
= 1;
fprintf (stderr,
"Division by zero, l%d,c%d-l%d,c%d",
@3.first_line, @3.first_column,
@3.last_line, @3.last_column);
}
}
就像对语义值一样,有一个每当规则被匹配时的位置的默认动作. 它将@的开始设置为第一个符号的开始并将@的末尾设为最后一个符号的末尾.
可以通过使用这个默认的动作来实现位置追踪的全自动. 上面的例子可以简单地这样重写:
exp: …
| exp '/' exp
{
if ($3)
= 1 / 3; else {
= 1;
fprintf (stderr,
"Division by zero, l%d,c%d-l%d,c%d",
@3.first_line, @3.first_column,
@3.last_line, @3.last_column);
}
}
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
6.3 位置的默认动作-Default Action for Locations
实际上,动作并不是计算位置的最好地方. 由于位置比语义值更普遍, 所以在输出的分析器里有用来重定义每个规则的默认动作(注:对位置的)的空间. YYLLOC_DEFAULT宏每当一个规则被匹配而关联的动作尚未执行之前被调用. 当处理一个语法错误要计算错误的位置的时候,它也会被调用.
大多数时候, 这个宏足以胜过语义动作中专注于位置的代码.
YYLOC_DEFAULT宏带有三个参数. 第一个是组(计算结果)的位置. 当匹配一个规则时, 第二个参数标识了正在匹配的规则的所有右端元素的位置, 第三个参数是规则右端元素的大小; 当处理一个语法错误的时候, 第二个参数标识了在错误处理中丢弃的符号的位置, 第三个参数是丢弃符号的数量.
YYLOC_DEFAULT默认地被这样定义:
define YYLLOC_DEFAULT(Current, Rhs, N) /
do /
if (N) /
{ /
(Current).first_line = YYRHSLOC(Rhs, 1).first_line; /
(Current).first_column = YYRHSLOC(Rhs, 1).first_column; /
(Current).last_line = YYRHSLOC(Rhs, N).last_line; /
(Current).last_column = YYRHSLOC(Rhs, N).last_column; /
} /
else /
{ /
(Current).first_line = (Current).last_line = /
YYRHSLOC(Rhs, 0).last_line; /
(Current).first_column = (Current).last_column = /
YYRHSLOC(Rhs, 0).last_column; /
} /
while (0)
当k是正数的时候, 函数YYRHSLOC (rhs,k)返回的是第k个符号的位置. 当k和位置n都为零的时候, YYRHSLOC(rhs,k)返回的是刚刚被归约的符号的位置.
当要自己定义宏YYLLOC_DEFAULT的时候,你要考虑以下几点:
所有的参数应该不受左端/右端的限制. 然而,只有第一个(结果)应该被YYLOC_DEFAULT修改.
出于与语义动作一致性的考虑, 右手端有效索引的范围应该是从1到n. 当n是0的时候,只有0是有效索引并且它引用的是归约前的那个符号. 在错误处理中,n总是正数.
因为实际的参数可能不在括号内, 如果需要的话,你应该加参数放在括号内. 同样地,当你的宏后紧跟一个分号时, 它应该被展开成可作为单独语句使用的东西.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
7 Bison声明-Bison Declarations
Bison声明(Bison declarations)部分定义了用来描述语法的符号和语义值的数据类型. 参阅 符号-Symbols.
所有符号类型名称(但不是如'+'和'*'的单字符记号)必须被声明. 如果你要指明非终结符语义值的数据类型的话,那么它们也必须被声明 (参阅多种值类型-More Than One Value Type一章).
默认地,文件的第一个规则也指明了开始符号. 如果你要其它的符号作为开始符号,你必须显示显式地声明它. (参阅语言与上下文无关文法-Language and Context-Free Grammars一章)
7.1 符号类型名称-Token Type Names 声明终结符
3.7.2 操作符优先级-Operator Precedence 声明终结符的优先级和结合性
3.7.3 值类型集-The Collection of Value Types 声明一组语义值类型
3.7.4 非终结符-Nonterminal Symbols 声明非终结语义值的类型
3.7.5 在分析执行前执行一些动作-Performing Actions before Parsing 在分析开始前执行的代码
3.7.6 释放被丢弃的符号-Freeing Discarded Symbols 声明如何释放符号
3.7.7 消除冲突警告-Suppressing Conflict Warnings 消除分析冲突时的警告
3.7.8 开始符号-The Start-Symbol 指明开始符号
3.7.9 纯(可重入)分析器-A Pure (Reentrant) Parser 请求一个可重入的分析器
3.7.10 Bison声明总结-Bison Declaration Summary 一个所有Bison声明的总结
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
7.1 符号类型名称-Token Type Names
声明符号类型(终结符)的最基本的方法如下:
%token name
Bison会在分析器中将这个声明转换成#define指令以便yylex(如果在这个文件中使用了它) 可以是用名称name代表这个记号类型码.
另外,如果你要指明结合性和优先级, 你可以使用%left,%right或者%nonassoc 代替%token. 参阅 操作符优先级-Operator Precedence.
你可以依靠附加一个十进制活十六进制整数紧跟着记号名称来显式地指定一个符号类型的数字码.
%token NUM 300
%token XNUM 0x12d // a GNU extension 一个GNU扩展
然而,我们通常最好让Bison选择所有记号类型的数字码. Bison会自动地选择互不冲突或不与其它字符冲突的码.
当栈类型是一个联合体的时候, 你必须使用%token或者其它记号声明来指明记号的语义值类型. 语义值类型由中括号分隔. (参阅多种值类型-More Than One Value Type一章).
例如:
%union { /* define stack type / / 定义栈类型 */
double val;
symrec tptr;
}
%token
将文字串写在%token声明的结尾, 你可以把一个符号类型名称关联到文字串记号上. 例如:
%token arrow "=>"
例如,一个C语言语法可以用同等的文字串记号指明这些名称
%token
%token
%left OR "<="
一旦你使文字串和符号名称等价, 你可以在以后的声明或者语法规则中交替地使用它们. yylex函数可以使用符号名称或者文字串来获得符号类型数字码. (参阅调用惯例-Calling Convention一章).
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
7.2 操作符优先级-Operator Precedence
使用%left,%right或者%nonassoc 可以一次声明一个记号并指明它的优先级和结合性. 这些被称做优先级声明(precedence declarations). 获取更多这方面的信息,参阅 操作符优先级-Operator Precedence.
优先级的声明与%token的声明相同,或者是
%left symbols…
或者是
%left
这些声明都与%token的目的相同. 但是额外地,它们还指明了symbols的结合性和相对优先级:
操作符的结合性决定了如何重复使用嵌套的操作符: x op y op z' 是先组合x和y,还是先组合y和z. %left指明左结合性(先组合x和y)而 %right指明了有结合性(先组合y和z). %nonassoc指明了无结合性,即x op y op z' 被认为是一个语法错误.
一个操作符的优先级决定了它如何与另外的操作符嵌套使用. 在一个优先级声明中声明的所有记号有相同的优先级, 如何嵌套使用它们取决于它们的结合性. 当两个记号在不同的优先级声明中,稍晚声明的拥有更高的优先级,并且先被组合.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
7.3 值类型集-The Collection of Value Types
%union声明指明了语义值全部可能的数据类型集. 关键字%union后紧跟包含了C语言union同样的东西的一对大括号.
例如:
%union {
double val;
symrec *tptr;
}
这说明了两个可选择的类型是double和symrec*. 它们被赋予了名称val和tptr; 这些名称用于在%toke和%type声明中为终结符或非终结符选择一个类型. (参阅非终结符-Nonterminal Symbols一章).
作为一个POSIX扩展,一个标志被允许紧跟在union后. 例如:
%union value {
double val;
symrec *tptr;
}
指明了联合题标志value,所以相应的C类型为union value. 如果你不知名一个标志,它默认地就为YYSTYPE.
我们应该注意到,并不像C语言中的union声明一样, 在Bison中,你不需要在大括号结束的时候写上分号.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
7.4 非终结符-Nonterminal Symbols
当你使用%union指明多种值类型的时候, 你必须为每个要使用其语义值的非终结符指明一个值类型. 通过%type可以做到这一点,像这样:
%type
这里的nonterminal是非终结符的名称, type是在%union中给定的名称来指定该非终结符的语义值类型. (参阅值类型集-The Collection of Value Types一章). 你可以给任意多数量的非终结符以相同的数据类型, 如果它们有相同的值类型的话. 这时我们要使用空白来分隔符号名称.
你也可以声明一个终结符的值类型. 为终结符使用相同的
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
7.5 在分析执行前执行一些动作-Performing Actions before Parsing
有些时候,你的分析器需要在分析之前执行一些初始化. 通过使用%initial-action指令指定这种代码.
指令: %initial-action { code }
声明了code必须在每次调用yyparse之前被调用. code可以使用来指明与symbols关联的语义值. 其余的分析器参数也是可用的. (参阅分析器函数yyparse-The Parser Funcation yyparse一章).
警告:对于版本1.875来说,这个特征仍然是实验性的. 主要原因是没有足够的用户反馈. 相应的语法仍可能会改变.
例如:
%union
{
char *string;
}
%token
%type
%destructor { free (
像一个变量一样工作,这个变量包含了由当前规则构成的组的语义值. 参阅 动作-Actions.
变量: $n
像一个变量一样工作,这个变量包含了当前动作第n个部件的语义值. 参阅 动作-Actions.
变量:
类似
在动作中,规则左端的语义值. 参阅 动作-Actions.
变量: $n
在动作中,规则右端第n个符号的语义值. 参阅 动作-Actions.
分隔符: %%
用于分隔语法规则部分和Bison声明部分或者epilogue部分. 参阅 Bison语法文件的布局-The Overall Layout of a Bison Grammar.
分隔符: %{code%}
在%{'和%}'之间的代码不做任何解释被直接复制到输出文件. 这些代码组成了输入文件的Prologue部分. 参阅 Bison语法的提纲-Outline of a Bison Grammar.
结构: /…/
注释分隔符,类似C.
分隔符: :
分隔动作的结果和它的部件. 参阅 描述语法规则的语法-Syntax of Grammar Rules.
分隔符: ;
结束一个规则. 参阅 描述语法规则的语法-Syntax of Grammar Rules.
分隔符: |
分隔同一个非终结符结果的不同规则. 参阅 描述语法规则的语法-Syntax of Grammar Rules.
符号: accept 预定义非终结符, 它的唯一规则为`accept: start $end', 这里的start是开始符号. 参阅 开始符号- The Start-Symbol. 它不能在语法中使用.
指令: %debug
激活分析器调试. 参阅 声明总结-Decl Summary.
指令: %defines
为扫描器创建一个头文件的Bison声明. 参阅 声明总结-Decl Summary.
指令: %destructor
指明分析器如何回收被丢弃符号相关的内存. 参阅 释放丢弃的符号- Freeing Discarded Symbols.
指令: %dprec
在分析的时候赋予规则一个优先级来解决归约/归约冲突的Bison声明. 参阅 编写GLR分析器-Writing GLR Parsers.
符号: $end
用来标记流结束的预定义记号,不能在语法中使用.
符号: error
一个保留的用于错误恢复的记号名称. 这个记号可以用在语法规则中用来允许Bison分析器在不终止处理的前提下识别一个错误. 实际上,一个包含错误的句子可被认为是有效的. 遇到一个语法错误时, 记号error成为了当前的超前扫描记号. 与error相应的动作被执行,并且超前扫描记号被重置为最初引起错误的记号. 参阅 错误恢复-Error Recovery.
指令: %error-verbose
请求冗长模式的Bison声明, 指明了当调用yyerror时的错误消息字符串.
指令: %file-prefix="prefix"
设置输出文件前缀的Bison声明.参阅 声明总结-Decl Summary.
指令: %glr-parser
声称GLR分析器的Bison声明. 参阅 编写GLR分析器-Writing GLR Parsers.
指令: %initial-action
在分析器前运行代码.参阅 在分析前执行动作- Performing Actions before Parsing.
指令: %left
为操作符指定左结合性的Bison声明. 参阅 操作符优先级-Operator Precedence.
指令: %lex-param {argument-declaration}
指明yylex的额外参数的Bison声明. 参阅 纯分析器的调用惯例-Calling Conventions for Pure Parsers.
指令: %merge
赋予规则一个合并函数的Bison声明. 如果有一个归约/归约冲突的规则带有相同的合并函数, 那么这个函数被应用于两个语义值来获得单一的结果. 参阅 Writing GLR Parsers-编写GLR分析器.
指令: %name-prefix="prefix"
重命名外部符号的Bison声明.参阅 声明总结-Decl Summary.
指令: %no-lines
在分析器文件中避免产生#line指令的Bison声明. 参阅 声明总结-Decl Summary.
指令: %nonassoc
声明一个无结合性记号. 参阅 操作符优先级-Operator Precedence.
指令: %output="filename"
设置分析器文件的Bison声明 参阅 声明总结-Decl Summary.
指令: %parse-param {argument-declaration}
指定yyparse接受的额外参数的Bison声明. 参阅 分析器函数yyparse- The Parser Function yyparse.
指令: %prec
给特定的规则指定优先级的Bison声明. 参阅 上下文依赖优先级-Context-Dependent Precedence.
指令: %pure-parser
请求一个纯(可重入)分析器的Bison声明. 参阅 一个纯(可重入)分析器-A Pure (Reentrant) Parser.
指令: %right
指定记号右结合性的Bison声明. 参阅 操作符优先级-Operator Precedence.
指令: %start
指定开始符号的Bison声明参阅 开始符号-The Start-Symbol.
指令: %token
声明记号但不指定优先级. 参阅 记号类型名称-Token Type Names.
指令: %token-table
在分析器文件中加入符号名称表的Bison声明. 参阅 声明总结-Decl Summary.
指令: %type
声明非终结符的Bison声明. 参阅 非终结符-Nonterminal Symbols.
符号: $undefined
所有yylex返回的未定义值被映射到这个预定义符号. 它不能在语法中使用,[untranslated]rather,use error.
指令: %union
指定多种可能语义值数据类型的Bison声明. 参阅 值类型集-The Collection of Value Types.
宏: YYABORT
通过使yyparse立即返回1,来伪装发生一个未恢复的语法错误的宏. 并不调用错误报告函数yyerrpr. 参阅 分析器函数ppyarse-The Parser Function yyparse.
宏: YYACCEPT
通过使yyparse立即返回0,来伪装语言的一个完整的表达已经被读取的宏. 参阅 分析器函数ppyarse-The Parser Function yyparse.
宏: YYBACKUP
从分析器栈中丢弃一个值并伪造一个超前扫描记号的宏. 参阅 在动作中使用的特殊特征-Special Features for Use in Actions.
变量: yychar
包含当前超前扫描记号的正数值的外部整数变量. (在一个纯分析器中,它是一个在yyparse中的局部变量). 错误恢复规则可能要检查这个变量. 参阅 在动作中使用的特殊特征-Special Features for Use in Actions.
变量: yyclearin
在错误恢复规则中使用的宏.它清除先前的超前扫描记号. 参阅 错误恢复-Error Recovery.
宏: YYDEBUG
使分析器带有追踪代码的宏. 参阅 跟踪你的分析器-Tracing Your Parser.
变量: yydebug
默认被置0的外部整数变量. 如果yydebug被赋予一个非零值, 分析器会输入关于输入符号和分析器动作的信息. 参阅 跟踪你的分析器-Tracing Your Parser.
宏: yyerrok
使分析器在一个语法错误之后立即恢复到正常模式的宏. 参阅 错误恢复-Error Recovery.
宏: YYERROR
一个假装刚刚发现一个语法错误的宏: 调用yyerror然后执行通常的错误恢复如果可能的话(参阅错误恢复-Error Recovery一章) 或者(如果恢复是不可能的)使yyparse返回1. 参阅 错误恢复-Error Recovery.
函数: yyerror
用户提供的当发现错误时被yyparse调用的函数. 参阅 错误报告函数yyerror-The Error Reporting Function yyerror.
宏: YYERROR_VERBOSE
一个在Prologue部分用#define定义的陈旧的宏, 当调用yyerror时,它请求详细的错误消息字符串. 你把YYERROR_VERBOSE定义成什么东西并没有影响, 有影响的只是你是否定义了它. 使用%error-verbose是更好的选择.
宏: YYINITDEPTH
指定分析器栈初始大小的宏. 参阅 栈溢出-Stack Overflow.
函数: yylex
用户提供的词法分析器函数, 不带有任何参数来获得下一个记号. 参阅 词法分析器函数yylex-The Lexical Analyzer Function yylex.
宏: YYLEX_PARAM
一个用于指明yyparse传递到yylex的额外参数(或者额外参数列表)的陈旧的宏. 不赞成继续使用这个宏,它只被Yacc类似分析器支持. 参阅 纯分析器的调用惯例-Calling Conventions for Pure Parsers.
变量: yylloc
yylex应该将一个记号的行列号放入这个外部变量. (在纯分析器中,它是一个yyparse的局部变量, 它的地址被传递到yylex). 如果你在语法动作中不使用`@'特性,你可以忽略这个变量. 参阅 记号的文字位置-Textual Locations of Tokens.
Type: YYLTYPE
yyloc的数据类型;默认地为一个带有四个成员的结构体. 参阅 位置的数据类型-Data Types of Locations.
变量: yylval
yylex应该将记号相关的语义值放入这个变量. (在纯分析器中,它是一个yyparse中的局部变量,并且它的地址被传递到yylex.) 参阅 记号的语义值-Semantic Values of Tokens.
宏: YYMAXDEPTH
指明分析器栈最大容的宏. 参阅 栈溢出-Stack Overflow.
变量: yynerrs
一个全局变量,每次出现语法错误时自增1. (在纯分析器中,它是一个yyparse中的局部变量.) 参阅 错误报告函数yyerror-The Error Reporting Function yyerror.
函数: yyparse
Bison产生的分析器函数;调用这个函数开始分析. 参阅 分析器函数yyparse-The Parser Function yyparse.
宏: YYPARSE_PARAM
指明yyparse应该接受的参数名成的陈旧宏. 不赞成继续使用这个宏,它只被Yacc类似分析器支持. 参阅 纯分析器的调用惯例-Calling Conventions for Pure Parsers.
宏: YYRECOVERING
一个宏,它的值指明了分析器是否正在从错误中恢复. 参阅 动作中使用的特殊特征-Special Features for Use in Actions.
宏: YYSTACK_USE_ALLOCA
用于控制当C语言LALR(1)分析器需要扩展它的栈时,alloca的使用. 如果定义为0,分析器会使用malloc来扩展它的栈. 如果定义为1,分析器则会使用alloca. 除了0和1以外的值保留用于Bison以后的扩展. 如果没有被定义, YYSTACK_USA_ALLOCA默认为0.
如果你定义YYSTACK_USE_ALLOCA为1, 你有责任使alloca是可见的, 例如,使用GCC,或者包含<stdlib.h>. 此外,在更普通的情况下, 如果你的代码可能运行在一个有限栈容量和不可信任栈溢出检查的主机上的时候, 你应将YYMAXDEPTH设为当调用alloca时, 在一个在任何目标主机不会产生栈溢出的值. 你可以检查Bison生成的代码来决定适当的数值. 这需要在底层详细实现的专业技术.
类型: YYSTYPE
语义值的数据类型;默认为int. 参阅 语义值的数据类型-Data Types of Semantic Values.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
B. 词汇表-Glossary
Backus-Naur Form (BNF; also called "Backus Normal Form")
Backus-Naur 范式 (BNF; 也被称为 "Backus正规范式")
由John Backus倡导的,最初用于描述上下文无关文法的正式方法. 在Peter Naur他的称为Algol60报告的1960-01-02委员会文档中得到少许改进. 参阅 语言与上下文无关文法-Languages and Context-Free Grammars.
Context-free grammars
上下文无关文法
描述可以使用而不考虑上下文的规则的文法. 因此,如果有一个规则说一个整数可做为一个表达式使用, 那么,整数在任何地方都是一个允许的表达式. 参阅 语言与上下文无关文法-Languages and Context-Free Grammars.
Dynamic allocation
动态分配
在执行期间分配内存,而不是在编译期间或者进入一个函数时.
Empty string
空字符串
模拟集合论中的空集, 空字符串是长度为0的字符串.
Finite-state stack machine
有限状态栈机
一种含有多种离散状态的机器,每个时刻只有一种状态. 当处理输入的时候,机器按照机器逻辑的指定从一个状态转换到另一个状态. 对于分析器来说,输入就是要分析的语言, 状态对应于语法规则中的各个阶段. 参阅 Bison分析器算法-The Bison Parser Algorithm.
Generalized LR (GLR)
通用LR (GLR)
一种可以处理包括那些不是LALR(1)的上下文无关文法的分析算法. 它用来解决Bison通常的LALR(1)算法不能解决的冲突. 它高效地分裂成多个分析器,尝试所有可能的分析,丢弃那些在额外上下文提示下失败的分析器. 参阅 通用LR分析-Generalized LR Parsing.
Grouping
分组
一个(通常)在语法上可再分的语言结构; 例如C中的`expression'或者'declaration'. 参阅 语言和上下文无关文法-Languages and Context-Free Grammars.
Infix operator
中缀操作符
放置在操作数中间指定某些操作的算术操作符.
Input stream
输入流
在设备或程序间的连续数据流.
Language construct
语言结构
一种语言的典型应用模式. 例如,一种C语言的结构是if语句. 参阅 语言和上下文无关文法-Languages and Context-Free Grammars.
Left associativity
左结合性
拥有左结合性的操作符被从左至右地分析: a+b+C'首先计算a+b'然后和`c'一起计算. 参阅 操作符优先级-Operator Precedence.
Left recursion
左递归
一个结果符号同样是第一个部件符号的规则; 例如: `expseq1 : expseq1 ',' exp;'. 参阅 递归规则-Recursive Rules.
Left-to-right parsing
自左至右分析
同过自左至右分析一个个地分析记号来分析一个句子. 参阅 Bison 分析器算法-The Bison Parser Algorithm.
Lexical analyzer (scanner)
词法分析器 (扫描器)
一个读取输入流并逐个返回记号的函数. 参阅 词法分析器函数yylex-The Lexical Analyzer Function yylex.
Lexical tie-in
词法关联
一个由语法规则动作设置的标志用来改变分析记号的方法. 参阅 词法关联-Lexical tie-in.
Literal string token
字符串文字记号
一个由两个或者更多字符组成的记号.参阅 符号-Symbols.
Look-ahead token
超前扫描记号
一个已经读取但未移进的记号. 参阅 超前扫描记号-Look-Ahead Tokens.
LALR(1)
一种Bison(像大多数其它分析器一样)可以处理的上下文无关文法. LR(1)的子集. 参阅 令人迷惑的归约/归约冲突-Mysterious Reduce/Reduce Conflicts.
LR(1)
一种上下文无关文法, 它在大多数时侯需要一个超前扫描记号来消除任何输入片段的歧义.
Nonterminal symbol
非终结符
一个代表可以通过规则表达为更小结构的语法结构; 换句话说,一个不是记号的结构. 参阅 符号-Symbols.
Parser
分析器
一个靠分析从词法分析器传递过来的记号的语法结构来识别有效句子的函数.
Postfix operator
后缀操作符
放置在操作数后执行某些操作的算术操作符.
Reduction
归约
依照一个语法规则将非终结符和/或终结符的序列替换为非终结符. 参阅 Bison分析器算法-The Bison Parser Algorithm.
Reentrant
可重入
一个可重入的子程序是一个可以被任意次地并行调用并且调用间相互不干扰的子程序. 参阅 一个纯(可重入)分析器-A Pure (Reentrant) Parser.
Reverse polish notation
逆波兰记号
一种所有操作符都是后缀操作符的语言.
Right recursion
右递归
一个结果记号也是它最后部件记号的规则; 例如 `expseq1: exp ',' expseq1;'. 参阅 递归规则-Recursive rules.
Semantics-语义
在计算机语言中,语义由每个语言实例的动作指明, 例如,每个语句的意义. 参阅 定义语言的语义-Defining Language Semantics.
Shift-移进
我们说一个分析器移进当它决定进从流中进一步分析输入而不是立即归约一些已经识别的规则. 参阅 Bison分析器算法-The Bison Parser Algorithm.
Single-character literal
单字符文字
一个被识别和解释为它自己的单一字符. 参阅 从正规文法转换到Bison输入-From Formal Rules to Bison Input.
Start symbol
开始符号
代表要分析语言的一个完整有效的表述的非终结符. 在语言描述中,开始符号通常被列为第一个非终结符. 参阅 开始符号-The Start-Symbol.
Symbol table
符号表
用来识别和使用已经存在的符号信息的数据结构. 在进行分析器符号表存储符号名称和相关数据. 参阅 多功能计算器-Multi-function Calc.
Syntax error
语法错误
一个发生在分析无效语法的输入流时的错误. 参阅 错误恢复-Error Recovery.
Token
记号
一个基本的不可再分的语言单元. 在语法中,描述一个记号的符号是终结符. Bison分析器的输入是来自词法分析器的记号流. 参阅 Symbols-符号.
Terminal symbol
终结符
在语法中不包含含规则因此语法上不可再分的语法符号. 它表示的输入片段是一个记号. 参阅 语言与上下文无关文法-Languages and Context-Free Grammars.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
C. 复制这个手册-Copying This Manual
C.1 GNU Free Documentation License 复制这个手册的许可.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
C.1 GNU Free Documentation License
Version 1.2, November 2002
Copyright © 2000,2001,2002 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
PREAMBLE
The purpose of this License is to make a manual, textbook, or other functional and useful document free in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others.
This License is a kind of "copyleft", which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software.
We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference.
APPLICABILITY AND DEFINITIONS
This License applies to any manual or other work, in any medium, that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. Such a notice grants a world-wide, royalty-free license, unlimited in duration, to use that work under the conditions stated herein. The "Document", below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as "you". You accept the license if you copy, modify or distribute the work in a way requiring permission under copyright law.
A "Modified Version" of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language.
A "Secondary Section" is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (Thus, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them.
The "Invariant Sections" are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License. If a section does not fit the above definition of Secondary then it is not allowed to be designated as Invariant. The Document may contain zero Invariant Sections. If the Document does not identify any Invariant Sections then there are none.
The "Cover Texts" are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text may be at most 25 words.
A "Transparent" copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, that is suitable for revising the document straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup, or absence of markup, has been arranged to thwart or discourage subsequent modification by readers is not Transparent. An image format is not Transparent if used for any substantial amount of text. A copy that is not "Transparent" is called "Opaque".
Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML, PostScript or PDF designed for human modification. Examples of transparent image formats include PNG, XCF and JPG. Opaque formats include proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML, PostScript or PDF produced by some word processors for output purposes only.
The "Title Page" means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, "Title Page" means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text.
A section "Entitled XYZ" means a named subunit of the Document whose title either is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (Here XYZ stands for a specific section name mentioned below, such as "Acknowledgements", "Dedications", "Endorsements", or "History".) To "Preserve the Title" of such a section when you modify the Document means that it remains a section "Entitled XYZ" according to this definition.
The Document may include Warranty Disclaimers next to the notice which states that this License applies to the Document. These Warranty Disclaimers are considered to be included by reference in this License, but only as regards disclaiming warranties: any other implication that these Warranty Disclaimers may have is void and has no effect on the meaning of this License.
VERBATIM COPYING
You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3.
You may also lend copies, under the same conditions stated above, and you may publicly display copies.
COPYING IN QUANTITY
If you publish printed copies (or copies in media that commonly have printed covers) of the Document, numbering more than 100, and the Document's license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects.
If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages.
If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a computer-network location from which the general network-using public has access to download using public-standard network protocols a complete Transparent copy of the Document, free of added material. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public.
It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document.
MODIFICATIONS
You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version:
Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission.
List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has fewer than five), unless they release you from this requirement.
State on the Title page the name of the publisher of the Modified Version, as the publisher.
Preserve all the copyright notices of the Document.
Add an appropriate copyright notice for your modifications adjacent to the other copyright notices.
Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below.
Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice.
Include an unaltered copy of this License.
Preserve the section Entitled "History", Preserve its Title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified Version as given on the Title Page. If there is no section Entitled "History" in the Document, create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence.
Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the "History" section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission.
For any section Entitled "Acknowledgements" or "Dedications", Preserve the Title of the section, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein.
Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles.
Delete any section Entitled "Endorsements". Such a section may not be included in the Modified Version.
Do not retitle any existing section to be Entitled "Endorsements" or to conflict in title with any Invariant Section.
Preserve any Warranty Disclaimers.
If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles.
You may add a section Entitled "Endorsements", provided it contains nothing but endorsements of your Modified Version by various parties--for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard.
You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one.
The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version.
COMBINING DOCUMENTS
You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice, and that you preserve all their Warranty Disclaimers.
The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work.
In the combination, you must combine any sections Entitled "History" in the various original documents, forming one section Entitled "History"; likewise combine any sections Entitled "Acknowledgements", and any sections Entitled "Dedications". You must delete all sections Entitled "Endorsements."
COLLECTIONS OF DOCUMENTS
You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects.
You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document.
AGGREGATION WITH INDEPENDENT WORKS
A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, is called an "aggregate" if the copyright resulting from the compilation is not used to limit the legal rights of the compilation's users beyond what the individual works permit. When the Document is included in an aggregate, this License does not apply to the other works in the aggregate which are not themselves derivative works of the Document.
If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one half of the entire aggregate, the Document's Cover Texts may be placed on covers that bracket the Document within the aggregate, or the electronic equivalent of covers if the Document is in electronic form. Otherwise they must appear on printed covers that bracket the whole aggregate.
TRANSLATION
Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License, and all the license notices in the Document, and any Warranty Disclaimers, provided that you also include the original English version of this License and the original versions of those notices and disclaimers. In case of a disagreement between the translation and the original version of this License or a notice or disclaimer, the original version will prevail.
If a section in the Document is Entitled "Acknowledgements", "Dedications", or "History", the requirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title.
TERMINATION
You may not copy, modify, sublicense, or distribute the Document except as expressly provided for under this License. Any other attempt to copy, modify, sublicense or distribute the Document is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
FUTURE REVISIONS OF THIS LICENSE
The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See http://www.gnu.org/copyleft/.
Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License "or any later version" applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
C.1.1 ADDENDUM: How to use this License for your documents
To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page:
Copyright (C) year your name.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled ``GNU
Free Documentation License''.
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace the "with...Texts." line with this:
with the Invariant Sections being list their titles, with
the Front-Cover Texts being list, and with the Back-Cover Texts
being list.
If you have Invariant Sections without Cover Texts, or some other combination of the three, merge those two alternatives to suit the situation.
If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software.
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ 上层 ] [ >> ] [顶层] [内容] [索引] [ ? ]
索引-Index
跳转到: � � � � � � � � � � � � � � � � � � � � � � � � � � � � �
A B C E F G I L M P R
索引项 部分
--------------------------------------------------------------------------------
�
被丢弃的符号(discarded symbols) 3.7.6 释放被丢弃的符号-Freeing Discarded Symbols
编写一个词法分析器(writing a lexical analyzer) 2.1.3 rpcalc的词法分析器-The rpcalc Lexical Analyzer
编译分析器(compiling the parser) 2.1.7 编译分析器文件-Compiling the Parser File
--------------------------------------------------------------------------------
�
波兰记号计算器(polish notation calculator) 2.1 逆波兰记号计算器-Reverse Polish Notation Calculator
不确定性分析(non-deterministic parsing) 5.8 通用LR (GLR)分析-Generalized LR (GLR) Parsing
操作符的优先级(precedence of operators) 5.3 操作符优先级-Operator Precedence
操作符优先级(operator precedence) 5.3 操作符优先级-Operator Precedence
操作符优先级(operator precedence), 声明(declaring) 3.7.2 操作符优先级-Operator Precedence
--------------------------------------------------------------------------------
�
常见问题(frequently asked questions) 超前扫描记号(look-ahead token) 5.1 超前扫描记号-Look-Ahead Tokens
冲突(conflicts) 1.5 编写GLR分析器-Writing GLR Parsers
冲突(conflicts) 1.5.1 使用GLR分析器分析非歧义文法
冲突(conflicts) 5.2 移进/归约冲突-Shift/Reduce Conflicts
冲突(conflicts), 归约/归约(reduce/reduce) 5.6 归约/归约冲突-Reduce/Reduce Conflicts
冲突(conflicts), 消除警告(suppressing warnings of) 3.7.7 消除冲突警告-Suppressing Conflict Warnings
抽象语法树(abstract syntax tree) 10.5 实现跳转/循环-Implementing Gotos/Loops
--------------------------------------------------------------------------------
�
纯分析器(pure parser) 3.7.9 纯(可重入)分析器-A Pure (Reentrant) Parser
词法分析器(lexical analyzer) 4.2 词法分析器函数yylex-The Lexical Analyzer Function yylex
词法分析器(lexical analyzer), 编写(writing) 2.1.3 rpcalc的词法分析器-The rpcalc Lexical Analyzer
词法分析器(lexical analyzer), 目的(purpose) 1.7 Bison的输出:分析器文件-Bison Output: the Parser File
词法关联(lexical tie-in) 7.2 词法关联-Lexical Tie-ins
词汇表(glossary) B. 词汇表-Glossary
从错误中恢复(recovery from errors) 6. 错误恢复-Error Recovery
从语言接口(C-language interface) 4. 分析器C语言接口-Parser C-Language Interface
错误报告的规则(error reporting routine) 2.1.5 错误报告的规则-The Error Reporting Routine
错误报告函数(error reporting function) 4.3 错误报告函数yyerror-The Error Reporting Function yyerror
错误恢复(error recovery) 6. 错误恢复-Error Recovery
错误恢复(error recovery), 简单(simple) 2.3 简单的错误恢复-Simple Error Recovery
--------------------------------------------------------------------------------
�
单字符文字(single-character literal) 3.2 符号,终结符和非终结符-Symbols, Terminal and Nonterminal
递归规则(recursive rule) 3.4 递归规则-Recursive Rules
调试(debugging) 8.2 跟踪你的分析器-Tracing Your Parser
调用Bison(invoking Bison) 9. 调用Bison-Invoking Bison
--------------------------------------------------------------------------------
�
定义语言的语义(defining language semantics) 3.5 定义语言的语义-Defining Language Semantics
动作(action) 3.5.3 动作-Actions
动作(actions), 位置(location) 3.6.2 动作和位置-Actions and Locations
动作(actions), 语义(semantic) 1.4 语义动作
动作数据类型(action data types) 3.5.4 动作中值的数据类型-Data Types of Values in Actions
动作特征总结(action features summary) 4.4 在动作中使用的特殊特征-Special Features for Use in Actions
动作中的数据类型(data types in actions) 3.5.4 动作中值的数据类型-Data Types of Values in Actions
多功能计算器(multi-function calculator) 2.5 多功能计算器:mfcalc-Multi-Function Calculator: mfcalc
多字符文字(multicharacter literal) 3.2 符号,终结符和非终结符-Symbols, Terminal and Nonterminal
额外C代码部分(additional C code section) 3.1.4 Epilogue部分-The epilogue
--------------------------------------------------------------------------------
�
非确定性分析(non-deterministic parsing) 1.1 语言与上下文无关文法-Languages and Context-Free Grammars
非终结符(nonterminal symbol) 3.2 符号,终结符和非终结符-Symbols, Terminal and Nonterminal
非终结符(nonterminal), 没用处(useless) 8.1 理解你的分析器-Understanding Your Parser
分析错误(parse error) 4.3 错误报告函数yyerror-The Error Reporting Function yyerror
分析器(parser) 1.7 Bison的输出:分析器文件-Bison Output: the Parser File
分析器的算法(algorithm of parser) 5. Bison分析器算法-The Bison Parser Algorithm
分析器栈(parser stack) 5. Bison分析器算法-The Bison Parser Algorithm
分析器栈的溢出(overflow of parser stack) 5.9 栈溢出以及如何避免它-Stack Overflow, and How to Avoid It
分析器栈溢出(parser stack overflow) 5.9 栈溢出以及如何避免它-Stack Overflow, and How to Avoid It
分析器状态(parser state) 5.5 分析器状态-Parser States
符号(symbol) 3.2 符号,终结符和非终结符-Symbols, Terminal and Nonterminal
符号(symbols (abstract)) 1.1 语言与上下文无关文法-Languages and Context-Free Grammars
符号表实例(symbol table example) 2.5.3 mfcalc的符号表-The mfcalc Symbol Table
符号类型(token type) 3.2 符号,终结符和非终结符-Symbols, Terminal and Nonterminal
符号类型名称(token type names), 声明(declaring) 3.7.1 符号类型名称-Token Type Names
--------------------------------------------------------------------------------
�
规则(rule), 没用处(useless) 8.1 理解你的分析器-Understanding Your Parser
规则(rule), 指明的(pointed) 8.1 理解你的分析器-Understanding Your Parser
规则语法(rule syntax) 3.3 描述语法规则的语法-Syntax of Grammar Rules
规则中动作(mid-rule actions) 3.5.5 规则中的动作-Actions in Mid-Rule
归约(reduction) 5. Bison分析器算法-The Bison Parser Algorithm
归约/归约 冲突(reduce/reduce conflicts) 1.5 编写GLR分析器-Writing GLR Parsers
归约/归约冲突(reduce/reduce conflict) 5.6 归约/归约冲突-Reduce/Reduce Conflicts
归约/归约冲突(reduce/reduce conflicts) 1.5.1 使用GLR分析器分析非歧义文法
--------------------------------------------------------------------------------
�
核心(core), 项目集(item set) 8.1 理解你的分析器-Understanding Your Parser
核心(kernel), 项目集(item set) 8.1 理解你的分析器-Understanding Your Parser
--------------------------------------------------------------------------------
�
计算器(calculator), 多功能(multi-function) 2.5 多功能计算器:mfcalc-Multi-Function Calculator: mfcalc
计算器(calculator), 简单(simple) 2.1 逆波兰记号计算器-Reverse Polish Notation Calculator
计算器(calculator), 位置追踪(location tracking) 2.4 带有位置追踪的计算器:ltcalc-Location Tracking Calculator: ltcalc
计算器(calculator), 中缀符号(infix notation) 2.2 中缀符号计算器:calc-Infix Notation Calculator: calc
记号(token) 1.1 语言与上下文无关文法-Languages and Context-Free Grammars
记号(token), 没用处(useless) 8.1 理解你的分析器-Understanding Your Parser
简单例子的main函数(main function in simple example) 2.1.4 控制函数-The Controlling Function
简单实例(simple examples) 2. 实例-Examples
简介(introduction) Bison简介-Introduction
--------------------------------------------------------------------------------
�
接口(interface) 4. 分析器C语言接口-Parser C-Language Interface
结合性(associativity) 5.3.1 什么时候需要优先级-When Precedence is Needed
--------------------------------------------------------------------------------
�
警告(warnings), 阻止(preventing) 3.7.7 消除冲突警告-Suppressing Conflict Warnings
--------------------------------------------------------------------------------
�
开始符号(start symbol) 1.1 语言与上下文无关文法-Languages and Context-Free Grammars
开始符号(start symbol), (声明)declaring 3.7.8 开始符号-The Start-Symbol
可重入分析器(reentrant parser) 3.7.9 纯(可重入)分析器-A Pure (Reentrant) Parser
控制函数(controlling function) 2.1.4 控制函数-The Controlling Function
--------------------------------------------------------------------------------
�
练习(exercises) 2.6 练习-Exercises
--------------------------------------------------------------------------------
�
没用处的非终结符(useless nonterminal) 8.1 理解你的分析器-Understanding Your Parser
没用处的规则(useless rule) 8.1 理解你的分析器-Understanding Your Parser
没用处的记号(useless token) 8.1 理解你的分析器-Understanding Your Parser
--------------------------------------------------------------------------------
�
默认动作(default action) 3.5.3 动作-Actions
默认开始符号(default start symbol) 3.7.8 开始符号-The Start-Symbol
默认数据类型(default data type) 3.5.1 语义值的数据类型-Data Types of Semantic Values
默认位置类型(default location type) 3.6.1 位置的数据类型-Data Type of Locations
默认栈容量限制(default stack limit) 5.9 栈溢出以及如何避免它-Stack Overflow, and How to Avoid It
逆波兰记号(reverse polish notation) 2.1 逆波兰记号计算器-Reverse Polish Notation Calculator
--------------------------------------------------------------------------------
�
歧义文法(ambiguous grammars) 1.1 语言与上下文无关文法-Languages and Context-Free Grammars
歧义文法(ambiguous grammars) 5.8 通用LR (GLR)分析-Generalized LR (GLR) Parsing
--------------------------------------------------------------------------------
�
上下文无关文法(context-free grammar) 1.1 语言与上下文无关文法-Languages and Context-Free Grammars
上下文依赖优先级(context-dependent precedence) 5.4 上下文依赖优先级-Context-Dependent Precedence
声明(declarations) 3.1.1 Prologue部分-The prologue
声明(declarations), Bison 3.7 Bison声明-Bison Declarations
声明(declarations), Bison(简介)(Bison (introduction)) 3.1.2 Bison Declarations部分-The Bison Declarations Section
声明部分(declarations section) 3.1.1 Prologue部分-The prologue
声明操作符优先级(declaring operator precedence) 3.7.2 操作符优先级-Operator Precedence
声明符号类型名称(declaring token type names) 3.7.1 符号类型名称-Token Type Names
声明开始符号(declaring the start symbol) 3.7.8 开始符号-The Start-Symbol
声明文字串记号(declaring literal string tokens) 3.7.1 符号类型名称-Token Type Names
声明值类型(declaring value types) 3.7.3 值类型集-The Collection of Value Types
声明值类型(declaring value types), 非终结符(nonterminals) 3.7.4 非终结符-Nonterminal Symbols
声明总结(declaration summary) 3.7.10 Bison声明总结-Bison Declaration Summary
--------------------------------------------------------------------------------
�
实例(examples), 简单(simple) 2. 实例-Examples
使用Bison(using Bison) 1.8 使用Bison的流程-Stages in Using Bison 使用Bison的流程(stages in using Bison) 1.8 使用Bison的流程-Stages in Using Bison
释放被丢弃的符号(freeing discarded symbols) 3.7.6 释放被丢弃的符号-Freeing Discarded Symbols
--------------------------------------------------------------------------------
�
通用LR (GLR)分析(generalized LR (GLR) parsing) 5.8 通用LR (GLR)分析-Generalized LR (GLR) Parsing
通用LR(GLR)分析(generalized LR (GLR) parsing) 1.1 语言与上下文无关文法-Languages and Context-Free Grammars
通用LR(GLR)分析(generalized LR (GLR) parsing), 非歧义文法(unambiguous grammars) 1.5.1 使用GLR分析器分析非歧义文法
通用LR分析(generalized LR (GLR) parsing) 1.5 编写GLR分析器-Writing GLR Parsers
--------------------------------------------------------------------------------
�
位置(location) 1.6 位置-Locations
位置(location) 3.6 追踪位置-Tracking Locations
位置(location), 文字的(textual) 3.6 追踪位置-Tracking Locations
位置(location), 原文的(textual) 1.6 位置-Locations
位置的数据类型(data type of locations) 3.6.1 位置的数据类型-Data Type of Locations
位置动作(location actions) 3.6.2 动作和位置-Actions and Locations
位置追踪(location tracking calculator) 2.4 带有位置追踪的计算器:ltcalc-Location Tracking Calculator: ltcalc
文法(grammar), 上下文无关(context-free) 1.1 语言与上下文无关文法-Languages and Context-Free Grammars
文件格式(file format) 1.9 Bison语法文件的整体布局-The Overall Layout of a Bison Grammar
文字串记号(literal string token) 3.2 符号,终结符和非终结符-Symbols, Terminal and Nonterminal
文字记号(literal token) 3.2 符号,终结符和非终结符-Symbols, Terminal and Nonterminal
文字位置(textual location) 3.6 追踪位置-Tracking Locations
问题(questions) 10. 常见问题-Frequently Asked Questions
--------------------------------------------------------------------------------
�
相互递归-mutual recursion 3.4 递归规则-Recursive Rules
项目(item) 8.1 理解你的分析器-Understanding Your Parser
项目集核心(item set core) 8.1 理解你的分析器-Understanding Your Parser
项目集核心(item set core) 8.1 理解你的分析器-Understanding Your Parser
消除冲突警告(suppressing conflict warnings) 3.7.7 消除冲突警告-Suppressing Conflict Warnings
--------------------------------------------------------------------------------
�
悬挂else问题(dangling else) 5.2 移进/归约冲突-Shift/Reduce Conflicts
--------------------------------------------------------------------------------
�
一元操作符优先级(unary operator precedence) 5.4 上下文依赖优先级-Context-Dependent Precedence
移进(shifting) 5. Bison分析器算法-The Bison Parser Algorithm
移进/归约 冲突(shift/reduce conflicts) 1.5 编写GLR分析器-Writing GLR Parsers
移进/归约冲突(shift/reduce conflicts) 1.5.1 使用GLR分析器分析非歧义文法
移进/归约冲突(shift/reduce conflicts) 5.2 移进/归约冲突-Shift/Reduce Conflicts
--------------------------------------------------------------------------------
�
用于语法规则的语法(syntax of grammar rules) 3.3 描述语法规则的语法-Syntax of Grammar Rules
优先级(precedence), 上下文依赖(context-dependent) 5.4 上下文依赖优先级-Context-Dependent Precedence
优先级(precedence), 一元操作符(unary operator) 5.4 上下文依赖优先级-Context-Dependent Precedence
优先级声明(precedence declarations) 3.7.2 操作符优先级-Operator Precedence
有限状态机-finite-state machine 5.5 分析器状态-Parser States
右递归(right recursion) 3.4 递归规则-Recursive Rules
语法(grammar), Bison 1.2 从正规文法转换到Bison的输入-From Formal Rules to Bison Input
语法错误(syntax error) 4.3 错误报告函数yyerror-The Error Reporting Function yyerror
语法的规则部分(rules section for grammar) 3.1.3 语法规则部分-The Grammar Rules Section
语法规则部分(grammar rules section) 3.1.3 语法规则部分-The Grammar Rules Section
语法规则的语法(grammar rule syntax) 3.3 描述语法规则的语法-Syntax of Grammar Rules
语法文件(grammar file) 1.9 Bison语法文件的整体布局-The Overall Layout of a Bison Grammar
语法文件的格式(format of grammar file) 1.9 Bison语法文件的整体布局-The Overall Layout of a Bison Grammar
语法组(syntactic grouping) 1.1 语言与上下文无关文法-Languages and Context-Free Grammars
语言的语义(language semantics), 定义(defining) 3.5 定义语言的语义-Defining Language Semantics
语义动作(semantic actions) 1.4 语义动作
语义值(semantic value) 1.3 语义值-Semantic Values
语义值的数据类型(data types of semantic values) 3.5.1 语义值的数据类型-Data Types of Semantic Values
语义值类型(semantic value type) 3.5.1 语义值的数据类型-Data Types of Semantic Values
--------------------------------------------------------------------------------
�
原文位置(textual location) 1.6 位置-Locations
运行Bison(简介)(running Bison (introduction)) 2.1.6 运行Bison来产生分析器-Running Bison to Make the Parser
在规则中的动作(actions in mid-rule) 3.5.5 规则中的动作-Actions in Mid-Rule
--------------------------------------------------------------------------------
�
栈(stack), 分析器(parser) 5. Bison分析器算法-The Bison Parser Algorithm
栈溢出(stack overflow) 5.9 栈溢出以及如何避免它-Stack Overflow, and How to Avoid It
正规文法(formal grammar) 1.2 从正规文法转换到Bison的输入-From Formal Rules to Bison Input
--------------------------------------------------------------------------------
�
值(value), 语义(semantic) 1.3 语义值-Semantic Values
值类型(value type), 语义(semantic) 3.5.1 语义值的数据类型-Data Types of Semantic Values
值类型(value types), 非终结符(nonterminals), 声明(declaring) 3.7.4 非终结符-Nonterminal Symbols
值类型(value types), 声明(declaring) 3.7.3 值类型集-The Collection of Value Types
指明规则(pointed rule) 8.1 理解你的分析器-Understanding Your Parser
中缀符号计算器(infix notation calculator) 2.2 中缀符号计算器:calc-Infix Notation Calculator: calc
终结符(terminal symbol) 3.2 符号,终结符和非终结符-Symbols, Terminal and Nonterminal
--------------------------------------------------------------------------------
�
状态(分析器的)(state (of parser)) 5.5 分析器状态-Parser States
追踪分析器(tracing the parser) 8.2 跟踪你的分析器-Tracing Your Parser
字符串记号(string token) 3.2 符号,终结符和非终结符-Symbols, Terminal and Nonterminal
字符记号(character token) 3.2 符号,终结符和非终结符-Symbols, Terminal and Nonterminal
总结(summary), Bison声明(Bison declaration) 3.7.10 Bison声明总结-Bison Declaration Summary
总结(summary), 动作特征(action features) 4.4 在动作中使用的特殊特征-Special Features for Use in Actions
阻止有关冲突的警告(preventing warnings about conflicts) 3.7.7 消除冲突警告-Suppressing Conflict Warnings
组合(grouping),语法的(syntactic) 1.1 语言与上下文无关文法-Languages and Context-Free Grammars
左递归(left recursion) 3.4 递归规则-Recursive Rules
--------------------------------------------------------------------------------
A
AST 10.5 实现跳转/循环-Implementing Gotos/Loops
--------------------------------------------------------------------------------
B
Backus-Naur 范式(Backus-Naur form) 1.1 语言与上下文无关文法-Languages and Context-Free Grammars
Bison的调用选项(options for invoking Bison) 9. 调用Bison-Invoking Bison
Bison调用(Bison invocation) 9. 调用Bison-Invoking Bison
Bison分析器(Bison parser) 1.7 Bison的输出:分析器文件-Bison Output: the Parser File
Bison分析器算法(Bison parser algorithm) 5. Bison分析器算法-The Bison Parser Algorithm
Bison符号(Bison symbols), 表格(table of) A. Bison符号-Bison Symbols
Bison工具(Bison utility) 1.7 Bison的输出:分析器文件-Bison Output: the Parser File
Bison声明(Bison declarations) 3.7 Bison声明-Bison Declarations
Bison声明(简介)(Bison declarations (introduction)) 3.1.2 Bison Declarations部分-The Bison Declarations Section
Bison声明总结(Bison declaration summary) 3.7.10 Bison声明总结-Bison Declaration Summary
Bison语法(Bison grammar) 1.2 从正规文法转换到Bison的输入-From Formal Rules to Bison Input
Bison语法文件的布局(layout of Bison grammar) 1.9 Bison语法文件的整体布局-The Overall Layout of a Bison Grammar
Bison中的符号(symbols in Bison), 表格(table of) A. Bison符号-Bison Symbols
BNF 1.1 语言与上下文无关文法-Languages and Context-Free Grammars
--------------------------------------------------------------------------------
C
calc 2.2 中缀符号计算器:calc-Infix Notation Calculator: calc
conflicts 1.5.2 使用GLR解决歧义-Using GLR to Resolve Ambiguities
C代码(C code), 额外部分(section for additional) 3.1.4 Epilogue部分-The epilogue
--------------------------------------------------------------------------------
E
else, 悬挂(dangling) 5.2 移进/归约冲突-Shift/Reduce Conflicts
epilogue 3.1.4 Epilogue部分-The epilogue
--------------------------------------------------------------------------------
F
FDL, GNU Free Documentation License C.1 GNU Free Documentation License
--------------------------------------------------------------------------------
G
generalized LR (GLR) parsing, ambiguous grammars 1.5.2 使用GLR解决歧义-Using GLR to Resolve Ambiguities
GLR parsing, ambiguous grammars 1.5.2 使用GLR解决歧义-Using GLR to Resolve Ambiguities
GLR 分析(GLR parsing) 1.1 语言与上下文无关文法-Languages and Context-Free Grammars
GLR分析(GLR parsing) 1.5 编写GLR分析器-Writing GLR Parsers
GLR分析(GLR parsing) 5.8 通用LR (GLR)分析-Generalized LR (GLR) Parsing
GLR分析(GLR parsing), 非歧义文法(unambiguous grammars) 1.5.1 使用GLR分析器分析非歧义文法
GLR分析器和inline(GLR parsers and inline) 1.5.3 编译GLR分析器时需要考虑的问题-Considerations when Compiling GLR Parsers
--------------------------------------------------------------------------------
I
inline 1.5.3 编译GLR分析器时需要考虑的问题-Considerations when Compiling GLR Parsers
--------------------------------------------------------------------------------
L
LALR(1) 5.7 神秘的归约/归约冲突-Mysterious Reduce/Reduce Conflicts
LALR(1) 文法(LALR(1) grammars) 1.1 语言与上下文无关文法-Languages and Context-Free Grammars
LR(1) 5.7 神秘的归约/归约冲突-Mysterious Reduce/Reduce Conflicts
LR(1) 文法(LR(1) grammars) 1.1 语言与上下文无关文法-Languages and Context-Free Grammars
ltcalc 2.4 带有位置追踪的计算器:ltcalc-Location Tracking Calculator: ltcalc
--------------------------------------------------------------------------------
M
mfcalc 2.5 多功能计算器:mfcalc-Multi-Function Calculator: mfcalc
--------------------------------------------------------------------------------
P
Prologue 3.1.1 Prologue部分-The prologue
--------------------------------------------------------------------------------
R
reduce/reduce conflicts 1.5.2 使用GLR解决歧义-Using GLR to Resolve Ambiguities
rpcalc 2.1 逆波兰记号计算器-Reverse Polish Notation Calculator
--------------------------------------------------------------------------------
跳转到: � � � � � � � � � � � � � � � � � � � � � � � � � � � � �
A B C E F G I L M P R
--------------------------------------------------------------------------------
[顶层] [内容] [索引] [ ? ]
目录
Bison简介-Introduction
使用Bison的条件-Conditions for Using Bison
GNU GENERAL PUBLIC LICENSE
Preamble
Appendix: How to Apply These Terms to Your New Programs
1. 和Bison相关的一些基本概念-The Concepts of Bison
1.1 语言与上下文无关文法-Languages and Context-Free Grammars
1.2 从正规文法转换到Bison的输入-From Formal Rules to Bison Input
1.3 语义值-Semantic Values
1.4 语义动作
1.5 编写GLR分析器-Writing GLR Parsers
1.5.1 使用GLR分析器分析非歧义文法
1.5.2 使用GLR解决歧义-Using GLR to Resolve Ambiguities
1.5.3 编译GLR分析器时需要考虑的问题-Considerations when Compiling GLR Parsers
1.6 位置-Locations
1.7 Bison的输出:分析器文件-Bison Output: the Parser File
1.8 使用Bison的流程-Stages in Using Bison
1.9 Bison语法文件的整体布局-The Overall Layout of a Bison Grammar
2. 实例-Examples
2.1 逆波兰记号计算器-Reverse Polish Notation Calculator
2.1.1 rpclac的声明部分-Declarations for rpcalc
2.1.2 rpcalc的语法规则-Grammar Rules for rpcalc
2.1.2.1 解释input-Explanation of input
2.1.2.2 解释line-Explanation of line
2.1.2.3 解释expr-Explanation of expr
2.1.3 rpcalc的词法分析器-The rpcalc Lexical Analyzer
2.1.4 控制函数-The Controlling Function
2.1.5 错误报告的规则-The Error Reporting Routine
2.1.6 运行Bison来产生分析器-Running Bison to Make the Parser
2.1.7 编译分析器文件-Compiling the Parser File
2.2 中缀符号计算器:calc-Infix Notation Calculator: calc
2.3 简单的错误恢复-Simple Error Recovery
2.4 带有位置追踪的计算器:ltcalc-Location Tracking Calculator: ltcalc
2.4.1 ltcalc的Declarations-Declarations for ltcalc
2.4.2 ltcalc的语法规则-Grammar Rules for ltcalc
2.4.3 ltcalc的词法分析器-The ltcalc Lexical Analyzer.
2.5 多功能计算器:mfcalc-Multi-Function Calculator: mfcalc
2.5.1 mfcalc的声明-Declarations for mfcalc
2.5.2 mfcalc的语法规则-Grammar Rules for mfcalc
2.5.3 mfcalc的符号表-The mfcalc Symbol Table
2.6 练习-Exercises
3. Biosn的语法文件-Bison Grammar Files
3.1 Bison语法的提纲-Outline of a Bison Grammar
3.1.1 Prologue部分-The prologue
3.1.2 Bison Declarations部分-The Bison Declarations Section
3.1.3 语法规则部分-The Grammar Rules Section
3.1.4 Epilogue部分-The epilogue
3.2 符号,终结符和非终结符-Symbols, Terminal and Nonterminal
3.3 描述语法规则的语法-Syntax of Grammar Rules
3.4 递归规则-Recursive Rules
3.5 定义语言的语义-Defining Language Semantics
3.5.1 语义值的数据类型-Data Types of Semantic Values
3.5.2 多种值类型-More Than One Value Type
3.5.3 动作-Actions
3.5.4 动作中值的数据类型-Data Types of Values in Actions
3.5.5 规则中的动作-Actions in Mid-Rule
3.6 追踪位置-Tracking Locations
3.6.1 位置的数据类型-Data Type of Locations
3.6.2 动作和位置-Actions and Locations
3.6.3 位置的默认动作-Default Action for Locations
3.7 Bison声明-Bison Declarations
3.7.1 符号类型名称-Token Type Names
3.7.2 操作符优先级-Operator Precedence
3.7.3 值类型集-The Collection of Value Types
3.7.4 非终结符-Nonterminal Symbols
3.7.5 在分析执行前执行一些动作-Performing Actions before Parsing
3.7.6 释放被丢弃的符号-Freeing Discarded Symbols
3.7.7 消除冲突警告-Suppressing Conflict Warnings
3.7.8 开始符号-The Start-Symbol
3.7.9 纯(可重入)分析器-A Pure (Reentrant) Parser
3.7.10 Bison声明总结-Bison Declaration Summary
3.8 在同一个程序中使用多个分析器-Multiple Parsers in the Same Program
4. 分析器C语言接口-Parser C-Language Interface
4.1 分析器函数yyparse-The Parser Function yyparse
4.2 词法分析器函数yylex-The Lexical Analyzer Function yylex
4.2.1 yylex的调用惯例-Calling Convention for yylex
4.2.2 记号的语义值-Semantic Values of Tokens
4.2.3 记号的文字位置-Textual Locations of Tokens
4.2.4 纯分析器的调用惯例-Conventions for Pure Parsers
4.3 错误报告函数yyerror-The Error Reporting Function yyerror
4.4 在动作中使用的特殊特征-Special Features for Use in Actions
5. Bison分析器算法-The Bison Parser Algorithm
5.1 超前扫描记号-Look-Ahead Tokens
5.2 移进/归约冲突-Shift/Reduce Conflicts
5.3 操作符优先级-Operator Precedence
5.3.1 什么时候需要优先级-When Precedence is Needed
5.3.2 指定操作符的优先级-Specifying Operator Precedence
5.3.3 优先级使用的例子-Precedence Examples
5.3.4 优先级如何工作-How Precedence Works
5.4 上下文依赖优先级-Context-Dependent Precedence
5.5 分析器状态-Parser States
5.6 归约/归约冲突-Reduce/Reduce Conflicts
5.7 神秘的归约/归约冲突-Mysterious Reduce/Reduce Conflicts
5.8 通用LR (GLR)分析-Generalized LR (GLR) Parsing
5.9 栈溢出以及如何避免它-Stack Overflow, and How to Avoid It
6. 错误恢复-Error Recovery
7. 处理上下文依赖-Handling Context Dependencies
7.1 符号类型中的语义信息-Semantic Info in Token Types
7.2 词法关联-Lexical Tie-ins
7.3 词法关联和错误恢复-Lexical Tie-ins and Error Recovery
8. 调式你的分析器-Debugging Your Parser
8.1 理解你的分析器-Understanding Your Parser
8.2 跟踪你的分析器-Tracing Your Parser
9. 调用Bison-Invoking Bison
9.1 Bison选项-Bison Options
9.2 选项交叉键-Option Cross Key
9.3 Yacc库-Yacc Library
10. 常见问题-Frequently Asked Questions
10.1 分析器栈溢出-Parser Stack Overflow
10.2 我如何复位分析器-How Can I Reset the Parser
10.3 被销毁的字符串-Strings are Destroyed
10.4 C++分析器-C++ Parsers
10.5 实现跳转/循环-Implementing Gotos/Loops
A. Bison符号-Bison Symbols
B. 词汇表-Glossary
C. 复制这个手册-Copying This Manual
C.1 GNU Free Documentation License
C.1.1 ADDENDUM: How to use this License for your documents
索引-Index
--------------------------------------------------------------------------------
[顶层] [内容] [索引] [ ? ]
关于这个文档
这个文档由Charlie &在2005,六月,21使用王箫改进的texi2html 1.76生成.
导航面板的按钮有如下意义
按钮 名称 转到 From 1.2.3 go to
[ < ] Back 阅读顺序的上一章 1.2.2
[ > ] Forward 阅读顺序的下一章 1.2.4
[ << ] FastBack 章节的开始或上一章 1
[ 上层 ] Up 上层章节 1.2
[ >> ] FastForward 下一章 2
[顶层] Top 文档封面
[内容] Contents 目录
[索引] Index 索引
[ ? ] About 关于 (帮助)
这个 例子 假定当前的位置是在如下结构文档的 章节 1-2-3
1. 第一部分
1.1 章节 1-1
...
1.2 章节 1-2
1.2.1 章节 1-2-1
1.2.2 章节 1-2-2
1.2.3 章节 1-2-3 <== 当前位置
1.2.4 章节 1-2-4
1.3 章节 1-3
...
1.4 章节 1-4
--------------------------------------------------------------------------------
这个文档由Charlie &在2005,六月,21使用王箫改进的texi2html 1.76生成.
本文来自博客:
