实例介绍
Antlr4 文档 参考手册 官方
Early Praise for The Definitive ANTLR 4 Reference Parrs clear writing and lighthearted style make it a pleasure to learn the practical details of building language processors DDan bornstein Designer of the Dalvik VM for Android anTLR is an exceptionally powerful and flexible tool for parsing formal languages At Twitter, we use it exclusively for query parsing in our search engine. Our grammars are clean and concise, and the generated code is efficient and stable This book is our go-to reference for ANTLR v4-engaging writing, clear descriptions and practical examples all in one place Samuel luckenbill Senior manager of search infrastructure, Twitter, Inc antlR v4 really makes parsing easy, and this book makes it even easier. It explains every step of the process, from designing the grammar to making use of the output Niko Matsakis Core contributor to the rust language and researcher at Mozilla research i sure wish i had antlR 4 and this book four years ago when i started to work on a C++ grammar in the NetBeans IDE and the Sun Studio IDE. Excellent content and very readable Nikolay krasilnikov Senior software engineer, Oracle Corp This book is an absolute requirement for getting the most out of ANTLR. I refer to it constantly whenever I'm editing a grammar Rich Unger PrincipalmemberoftechnicalstaffApexCodeteamsSalesforce.com I have been using anTLR to create languages for six years now, and the new v4 is absolutely wonderful. The best news is that Terence has written this fantastic book to accompany the software. It will please newbies and experts alike. If you process data or implement languages, do yourself a favor and buy this book! Rahul gidwani Senior software engineer, Xoom Corp Never have the complexities surrounding parsing been so simply explained. This book provides brilliant insight into the ANTLR v4 software, with clear explanations from installation to advanced usage. An array of real-life examples, such as JSON and R, make this book a must-have for any ANTlR user David Morgan Student, computer and electronic systems, University of Strathclyde The Definitive antlr 4 Reference Terence parr The Pragmatic Bookshelf Dallas, Texas. Raleigh, North Carolina Pragmatic Bookshelf Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trade marks of The Pragmatic Programmers, LLC Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings)contained herein Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titlespleasevisitusathttp://pragprog.com Cover image by Babelstone(own work)[cc-by-sa-3.0(htTp: //creativecommons. org/licens es/by-sa/ 3.0), via Wikimedia Commons http://commons.wikimedia.org/wiki/file%3ashang_dynasty_inscribed_scapula.jpg The team that produced this book includes Susannah Pfalzer (editor) Potomac Indexing, LLC (indexer) Kim Wimpsett (copyeditor) David J Kelly (typesetter Janet Furlow ( producer) Juliet Benda〔 rights) Ellie Callahan(support) Copyright 2012 The Pragmatic Programmers, LLC rights reserved No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying recording or otherwise without the prior consent of the publisher Printed in the united states of americ SBN-13:978-1-93435-6999 Encoded using the finest acid-free high-entropy binary digits sook version: P1.0-January 2013 Contents Acknowledgments IX Welcome aboard! Part |-Introducing antlr and Computer Languages 1. Meet antLr 1.1 Installing ANTLR 1.2 Executing ANTLR and Testing Recognizers 2. The Big Picture 33699 2.1 Let's get meta! 2.2 Implementing parsers 11 2.3 You Cant Put Too much Water into a nuclear reactor 13 2.4 Building Language Applications Using Parse Trees 16 2.5 Parse- Tree Listeners and visitors 3. A Starter ANTLR Project 21 3.1 The antlR Tool. Runtime and Generated Code 22 3.2 Testing the Generated Parser 24 3.3 Integrating a Generated Parser into a Java Program 26 3.4 Building a Language Application 27 A Quick Tour 31 4.1 Matching an Arithmetic Expression Language 32 4.2 Building a Calculator Using a Visitor 38 4.3 Building a Translator with a Listener 42 4.4 Making Things Happen During the Parse 46 4.5 Cool Lexical Features 50 Contents·vi Part l- Developing language applications with antlr grammars 5. Designing grammars 57 5. 1 Deriving Grammars from Language Samples 58 5.2 Using Existing Grammars as a guide 60 5.3 Recognizing Common Language Patterns with ANTLR Grammars 61 5.4 Dealing with Precedence, Left Recursion, and associativity 69 5.5 Recognizing Common Lexical Structures 5.6 Drawing the Line Between Lexer and Parser 79 6. Exploring Some Real Grammars 83 6.1 Parsing Comma-Separated values 84 6.2 Parsing JSON 86 6.3 Parsing dot 93 6.4 Parsing Cymbal 98 6.5 Parsing R 102 7. Decoupling Grammars from Application-Specific Code 109 7.1 Evolving from Embedded Actions to Listeners 110 7.2 Implementing Applications with Parse-Tree Listeners 112 7.3 Implementing Applications with Visitors 115 7. 4 Labeling rule alternatives for Precise Event methods l17 7.5 Sharing Information Among Event Methods 119 8. Building Some Real Language Applications 127 8.1 Loading CSV Data 127 8.2 Translating uson to XML 130 8.3 Generating a Call Graph 134 8.4 Validating Program Symbol Usage 138 Part ll- Advanced topics 9. Error Reporting and Recovery 149 9.1 A Parade of errors 149 9.2 Altering and Redirecting ANTLR Error Messages 9.3 Automatic Error Recovery strategy 158 Contents·vi 9. 4 Error alternatives 170 9.5 Altering ANTLR,'s Error Handling Strategy 171 10. Attributes and actions 175 10.1 Building a Calculator with Grammar Actions 176 10.2 Accessing Token and Rule Attributes 182 10.3 Recognizing Languages Whose Keywords Arent Fixed 185 11. Altering the Parse with Semantic Predicates 189 1. 1 Recognizing Multiple Language dialects 190 11.2 Deactivating Tokens 193 11. 3 Recognizing ambiguous Phrases 196 12. Wielding Lexical Black Magic 203 12. 1 Broadcasting Tokens on Different Channels 204 12.2 Context-Sensitive Lexical Problems 208 12.3 Islands in the stream 219 12.4 Parsing and Lexing XML 224 Part v- Antlr Reference 13. Exploring the Runtime API 235 13.1 Library Package Overview 235 13.2 Recognizers 236 13.3 Input Streams of Characters and Tokens 238 13.4 Tokens and Token factories 239 13.5 Parse Trees 241 13.6 Error Listeners and strategies 242 13.7 Maximizing Parser Speed 243 13.8 Unbuffered Character and Token streams 243 13.9 Altering ANTLR,'s Code Generation 246 14. Removing Direct Left Recursion 247 14.1 Direct left-Recursive alternative patterns 248 142 Left-Recursive rule transformations 249 15. Grammar Reference 253 15.1 Grammar Lexicon 253 15.2 Grammar Structure 256 15.3 Parser rules 261 15.4 Actions and attributes 271 15.5 Lexer rules 277 ontents 15.6 Wildcard Operator and nongreedy subrules 283 15.7 Semantic Predicates 286 15.8 Options 292 15.9 ANTLR Tool Command-Line Options 294 Al. Bibliography 299 Index 301 【实例截图】
【核心代码】
标签:
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论