开发工具:
文件大小: 1mb
下载次数: 0
上传时间: 2010-06-01
详细说明: 前言 ANTLR是什么 ......................................................................................................................... 5 第1章 ANTLR规范: 元语言(Meta-Language) ......................................................................... 6 1.1元语言词汇表(Meta-Language Vocabulary) ................................................................. 6 1.2 Header段(Header Section) ......................................................................................... 12 1.3语法分析类的定义(Paser Class Definitions)............................. ............................... 12 1.4词法分析类定义(Lexcal Analyzer Class Definitions) ................................................... 13 1.5树分析类定义(Tree-parser Class Definitions) ............................................................. 14 1.6 选项段(Option Section) ....................................................................................... 14 1.7 记号段(Tokens Section) ....................................................................................... 14 1.8语法继承(Grammar Inheritance) ............................................................................ 16 1.9规则定义(Rule Definitions ) ....................................................................................... 16 1.10 原子的产生式元素(Atomic Production Elements) ................................................ 19 1.11 简单的产生式元素(Simple Production Elements) ................................................ 21 1.12产生式元素操作符(Production Element Operators)................................................ 22 1.13记号类 ............................................................................................................................ 24 1.14谓词 ............................................................................................................................... 24 1.15元素标签......................................................................................................................... 25 1.16 扩展的BNF规则元素(EBNF Rule Elements) ......................................................... 25 1.17 语义动作的解释(Interpretation Of Semantic Actions) .......................................... 26 1.18 语义谓词(Semantic Predicates) ............................................................................... 26 1.19语法谓词(Syntactic Predicates) ................................................................................. 28 1.19.1固定深度的超前预测分析和语法谓词(Fixed depth lookahead and syntactic predicates) ................................................................................................................... 29 1.20 ANTLR元语言文法(ANTLR-meta Lanuage Grammar) ........................................... 30 第2章 使用ANTLR进行词法分析(Lexical Analysis with ANTLR) .......................................... 30 2.1词法规则(Lexical Rules) .............................................................................................. 31 2.1.1跳过字符(Skipping characters) ...................................................................... 32 2.1.2词法分析规则的区别(Distinguishing between lexer rules) .......................... 32 2.1.3返回值(Return values)..................................................................................... 33 2.2含谓词的LL(k)词法分析 .................................................................................................. 34 2.3关键字和字面值(Keywords and literals) .................................................................... 37 2.4常见的前缀(Common prefixes) .................................................................................. 37 2.5记号定义文件(Token definition files) ......................................................................... 38 2.6字符类(Character classes) ........................................................................................... 38 2.7记号属性(Token Attributes) ........................................................................................ 38 2.8词法超前分析和记号结束符(Lexical lookahead and the end-of-token symbol) ....... 38 2.9扫描二进制文件(Scanning Binary Files) ..................................................................... 43 第3章 ANTLR的树分析器 ........................................................................................................... 44 3.1 什么是树分析器? .......................................................................................................... 45 3.2 可以分析什么类型的树? .............................................................................................. 45 3.3 树的语法规则.................................................................................................................. 46 3.4 句法断言.......................................................................................................................... 47 3.5 语义断言.......................................................................................................................... 48 3.6 一个树遍历器的例子 ...................................................................................................... 48 3.7 翻译 ................................................................................................................................ 51 3.8 一个树翻译的例子 .......................................................................................................... 51 3.9 检查/调试AST ................................................................................................................. 53 第4章 记号流(Token Streams) ............................................................................................... 54 4.1引言 ................................................................................................................................. 54 4.2自由通过记号流............................................................................................................... 55 4.3记号流过滤....................................................................................................................... 56 4.4记号流分离....................................................................................................................... 57 4.4.1例子........................................................................................................................ 58 4.4.2过滤器实现 ............................................................................................................ 59 4.4.3如何使用这个过滤器 ............................................................................................ 60 4.4.4树的创建................................................................................................................ 61 4.4.5垃圾回收................................................................................................................ 62 4.4.6附注........................................................................................................................ 62 4.5记号流多路技术 (又叫 "词法分析器多状态") ............................................................. 63 4.5.1多词法分析器 ........................................................................................................ 63 4.5.2词法分析器共享同一字符流 ................................................................................ 66 4.5.3分析多元记号流 .................................................................................................... 66 4.5.4多记号流超前扫描的效果 .................................................................................... 68 4.5.5多词法分析器vs调用另一条词法规则............................................................... 68 4.6 TokenStreamRewriteEngine 简单的语法制导翻译 ........................................................ 70 4.7 未来 ................................................................................................................................ 70 第5章 记号(token)词汇表...................................................................................................... 71 5.1引言 ................................................................................................................................. 71 5.1.1 ANTLR如何决定哪个词法符号是什么记号类型?............................................... 72 5.1.2为什么记号类型从4开始 .................................................................................... 72 5.1.3 ANTLR生成什么样的词汇表相关的文件 ............................................................ 72 5.1.4 ANTLR怎样同步在同一文件和不同文件里文法的符号类型映射..................... 72 5.2文法继承和词汇表 ........................................................................................................... 74 5.3识别器生成顺序............................................................................................................... 75 5.4词汇表的一些使用技巧 ................................................................................................... 76 第6章 错误处理及恢复 ............................................................................................................... 78 6.1、ANLTR的异常体系结构 ................................................................................................ 78 6.2 借助文法来修改默认的错误消息 ................................................................................. 81 6.3 解析异常处理 ................................................................................................................. 81 6.4 指定解析异常处理方法 ................................................................................................. 82 6.5 Lexer中的默认异常处理 .............................................................................................. 83 第7章Java Runtime Model ....................................................................................................... 85 第8章C++ Runtime Model ........................................................................................................ 85 第9章C# Runtime Model........................................................................................................... 85 第10章Python Runtime Model ................................................................................................. 85 第11章ANTLR树构建 ................................................................................................................... 85 11.1注释............................................................................................................................... 86 11.2 控制AST构建 ............................................................................................................... 86 11.3 构建AST的语法注释 ................................................................................................... 86 11.3.1叶节点 ................................................................................................................ 86 11.3.2 根节点 ............................................................................................................... 86 11.3.3 关闭标准树的构建 ........................................................................................... 87 11.3.4树节点构建 ........................................................................................................ 88 11.3.5 AST Action换化 .............................................................................................. 88 11.4 执行解析创建树 ........................................................................................................... 90 11.5 AST工厂 ........................................................................................................................ 90 11.6异类ASTs ....................................................................................................................... 92 11.6.1 一棵表达式树例子 ........................................................................................... 93 11.6.2 使用语法描述异构树 ..................................................................................... 100 11.7 AST(XML)序列化 ..................................................................................................... 101 11.8 AST枚举 ...................................................................................................................... 102 11.9 一些例子 ..................................................................................................................... 102 11.10 标签子规则 ............................................................................................................... 103 11.11 引用节点 ................................................................................................................... 107 11.12 必需的AST功能与形式 ........................................................................................... 107 第12章 语法继承(Grammar Inheritance) ............................................................................ 110 12.1 语法继承(Grammar Inheritance) ........................................................................... 110 12.2 功能(Functionality)................................................................................................. 113 12.3 父语法(Supergrammar)可以放置的位置 .............................................................. 115 12.4 错误信息(Error Messages) ..................................................................................... 116 第13章 选项(Options) .......................................................................................................... 116 13.1文件、语法和规则的选项(File, Grammar, and Rule Options) .............................. 116 13.1.1 ANTLR中支持的选项(Options supported in ANTLR) .................................. 118 13.1.2 language: 设置生成的目标语言 ...................................................................... 121 13.1.3 k: 设置 lookahead(前瞻)的深度 ................................................................ 121 13.1.4 importVocab: 初始化语法词汇表 .................................................................... 122 13.1.5 exportVocab: 指定导出词汇表的名称 ............................................................ 123 13.1.6 testLiterals: 是否生成常量检测代码 ............................................................... 124 13.1.7 defaultErrorHandler: 设置默认的错误处理器 ................................................ 125 13.1.8 codeGenMakeSwitchThreshold: 控制代码的生成 ........................................... 126 13.1.9 codeGenBitsetTestThreshold: 控制代码的生成 ............................................... 126 13.1.10 buildAST: 自动创建抽象语法树(AST) ....................................................... 127 13.1.11 ASTLabelType: 设置节点类型 ........................................................................ 127 13.1.12 charVocabulary: 设置词法分析器的字符表 .................................................. 128 13.1.13 warnWhenFollowAmbig ................................................................................... 129 13.2 命令行选项(Command Line Options) .................................................................... 131 ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.