admin管理员组

文章数量:1531437

2024年1月26日发(作者:)

Never have the complexities surrounding parsing been so simply explained. Thisbook provides brilliant insight into the ANTLR v4 software, with clear explanationsfrom installation to advanced usage. An array of real-life examples, such as JSONand R, make this book a must-have for any ANTlR userDavid MorganStudent, computer and electronic systems, University of StrathclydeThe Definitive antlr 4ReferenceTerence parrThe Pragmatic BookshelfDallas, Texas. Raleigh, North CarolinaPragmaticBookshelfMany of the designations used by manufacturers and sellers to distinguish their productsare claimed as trademarks. Where those designations appear in this book, and The PragmaticProgrammers, LLC was aware of a trademark claim, the designations have been printed ininitial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer,Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trademarks of The Pragmatic Programmers, LLCEvery precaution was taken in the preparation of this book. However, the publisher assumesno responsibility for errors or omissions, or for damages that may result from the use ofinformation (including program listings)contained hereinOur Pragmatic courses, workshops, and other products can help you and your team createbetter software and have more fun. For more information, as well as the latest PragmaticCover image by Babelstone(own work)[cc-by-sa-3.0(htTp: //creativecommons. org/licenses/by-sa/ 3.0), via Wikimedia CommonsThe team that produced this book includesSusannah Pfalzer (editor)Potomac Indexing, LLC (indexer)Kim Wimpsett (copyeditor)David J Kelly (typesetterJanet Furlow ( producer)Juliet Benda〔 rights)Ellie Callahan(support)

Copyright 2012 The Pragmatic Programmers, LLCrights reservedNo part of this publication may be reproduced, stored in a retrieval system, ortransmitted, in any form, or by any means, electronic, mechanical, photocopyingrecording or otherwise without the prior consent of the publisherPrinted in the united states of americSBN-13:978-1-93435-6999Encoded using the finest acid-free high-entropy binary digitssook version: P1.0-January 2013ContentsAcknowledgmentsIXWelcome aboard!Part |-Introducing antlrand Computer Languages1. Meet antLr1.1 Installing ANTLR1.2 Executing ANTLR and Testing Recognizers2. The Big Picture336992.1 Let's get meta!2.2 Implementing parsers112.3 You Cant Put Too much Water into a nuclear reactor132.4 Building Language Applications Using Parse Trees162.5 Parse- Tree Listeners and visitors3. A Starter ANTLR Project213.1 The antlR Tool. Runtime and Generated Code223.2 Testing the Generated Parser24

3.3 Integrating a Generated Parser into a Java Program263.4 Building a Language Application27A Quick Tour314.1 Matching an Arithmetic Expression Language324.2 Building a Calculator Using a Visitor384.3 Building a Translator with a Listener424.4 Making Things Happen During the Parse464.5 Cool Lexical Features50Contents·viPart l- Developing language applicationswith antlr grammars5. Designing grammars575. 1 Deriving Grammars from Language Samples585.2 Using Existing Grammars as a guide605.3 Recognizing Common Language Patterns with ANTLRGrammars615.4 Dealing with Precedence, Left Recursion, andassociativity695.5 Recognizing Common Lexical Structures5.6 Drawing the Line Between Lexer and Parser79

6. Exploring Some Real Grammars836.1 Parsing Comma-Separated values846.2 Parsing JSON866.3 Parsing dot936.4 Parsing Cymbal986.5 Parsing R1027. Decoupling Grammars from Application-Specific Code1097.1 Evolving from Embedded Actions to Listeners1107.2 Implementing Applications with Parse-Tree Listeners1127.3 Implementing Applications with Visitors1157. 4 Labeling rule alternatives for Precise Event methodsl177.5 Sharing Information Among Event Methods1198. Building Some Real Language Applications1278.1 Loading CSV Data1278.2 Translating uson to XML1308.3 Generating a Call Graph1348.4 Validating Program Symbol Usage138

Part ll- Advanced topics9. Error Reporting and Recovery1499.1 A Parade of errors1499.2 Altering and Redirecting ANTLR Error Messages9.3 Automatic Error Recovery strategy158Contents·vi9. 4 Error alternatives1709.5 Altering ANTLR,'s Error Handling Strategy17110. Attributes and actions17510.1 Building a Calculator with Grammar Actions17610.2 Accessing Token and Rule Attributes18210.3 Recognizing Languages Whose Keywords Arent Fixed18511. Altering the Parse with Semantic Predicates1891. 1 Recognizing Multiple Language dialects19011.2 Deactivating Tokens19311. 3 Recognizing ambiguous Phrases19612. Wielding Lexical Black Magic20312. 1 Broadcasting Tokens on Different Channels20412.2 Context-Sensitive Lexical Problems

20812.3 Islands in the stream21912.4 Parsing and Lexing XML224Part v- Antlr Reference13. Exploring the Runtime API23513.1 Library Package Overview23513.2 Recognizers23613.3 Input Streams of Characters and Tokens23813.4 Tokens and Token factories23913.5 Parse Trees24113.6 Error Listeners and strategies24213.7 Maximizing Parser Speed24313.8 Unbuffered Character and Token streams24313.9 Altering ANTLR,'s Code Generation24614. Removing Direct Left Recursion24714.1 Direct left-Recursive alternative patterns248142 Left-Recursive rule transformations24915. Grammar Reference253

本文标签: 官方参考手册