Javaによるパーサ構築技法 単行本 – 2001/11
Kindle 端末は必要ありません。無料 Kindle アプリのいずれかをダウンロードすると、スマートフォン、タブレットPCで Kindle 本をお読みいただけます。
Parser building is a powerful programming technique that opens a world of opportunity for designing how users interact with applications. By creating mini-languages, you can precisely address the requirements of your application development domain. Writing your own parsers empowers you to access a database more effectively than SQL to efficiently control the movement of an order through its workflow, to command the actions of a robot, and to control access privileges to transactions in a system. The repertoire of todays professional programmer should include the know-how to create custom languages. Building Parsers with Java shows how to create parsers that recognize custom programming languages. This book and its accompanying CD provide an in-depth explanation and clearly written tutorial on writing parsers, following the Interpreter Design Pattern. An easy-to-follow demonstration on how to apply parsers to vital development tasks is included, using more than a hundred short examples, numerous UML diagrams, and a pure Java parser toolkit to illustrate key points. You will learn *How to design, code, and test a working parser *How to create a parser to read a data language, and how --このテキストは、ペーパーバック版に関連付けられています。商品の説明をすべて表示する
This book explains how to write parsers for new computer languages that you create. Each chapter focuses on either background, techniques, or applications. A chart at the beginning of chapter one shows you which chapter focuses on each topic. Each chapter builds on the material presented in preceding chapters, so you should probably proceed through this book linearly. I review this book in the context of the table of contents:
1. Introduction - Just performs an overview of the book.
2. The Elements of a Parser - Explains what a parser is, introduces the building blocks of applied parsers, and shows how to compose new parsers from existing ones.
3. Building a Parser - Explains the steps in designing and coding a parser.
4. Testing a Parser - How to test a new language's features and also how to use random testing to detect ambiguity and other problems.
5. Parsing Data Languages - Shows how to create a parser that reads the elements of a data language. A data language is a set of strings that describe objects following a local convention.
6. Transforming a Grammar - How to ensure the correct behavior of operators in a language and how to avoid looping in a parser, which can follow from loops in a grammar.
7. Parsing Arithmetic - This chapter develops an arithmetic parser. Arithmetic usually appears as part of a larger language.
8. Parsing Regular Expressions - develops a regular expression parser. A regular expression is a string that uses symbols to describe a pattern of characters.
9. Advanced Tokenizing - Describes the tokenizers that are part of the Java programming language as well as the customizable tokenizer of this particular book. Tokenizing a string means breaking the string into logical nuggets so that you can define your parser in terms of these nuggets rather than individual characters.
10. Matching Mechanics - Explains how the fundamental types of parsers in this book match text.
11. Extending the Parser Toolkit - How to extend a parser toolkit which includes introducing new types of terminals or completely different parser types.
12. Engines - Introduces a logic engine, which is a piece of software that is able to return objects and groups of objects in response to a logical query.
13. Logic Programming - Shows how to program with facts and rules.
14. Parsing a Logic Language - How to construct a parser for a logic language. It shows how to build a parser for the Logikus programming language that was introduced in the previous chapter.
15. Parsing a Query Language - Constructs a parser for a query language. A query language parser translates textual queries into calls to an engine. The engine proves the query against a source of rules and data and returns successful proofs as the result of the query.
16. Parsing an Imperative Language - Shows how to create a parser for imperative languages. An imperative language parser translates a textual script into a composition of commands that direct a sequence of actions.
17. Directions - Points out areas for further reading and programming.
I used this book to create a parser for a visual language, and I found the instructions in this book very complete and helpful. I would recommend the following books if you are interested in getting deeper into the theory behind this book - "Programming Language Pragmatics" and also "Introduction to the Theory of Computation" by Sipser.
the provided code, and related concepts, are examined fully in the text. the code is so OOP-trivial ( this is a good Java design rather than rehashed procedural code clumsily ported to the OO-Language du-jour ) that anyone familiar with the basics of Java, C++ or C# should be able to compose their own library in a short period of time. in the preface the author suggests the reader be familiar with Design Patterns and UML, but he has included sections which address the minimal use he makes of UML. most 'somewhat experienced' programmers will be able to see through the scant UML diagrams to the underlying concepts they address, but he explains the notation anyway. as for Patterns, they are mentioned in passing but are not examined in any way which might hinder the uninitiated
one reviewer laments that ''... the author's explanation of his code library is virtually non-existent -- you're going to have to figure out what he's talking about all on your own'' - this was not the same book i read. in addition to including comprehensive javadoc ( Java documentation in HTML format is provided on the CD as well as his web site, if you're buying a used copy ) to help guide readers interested in ''digging into his code'', the author walks the reader through the concepts presented in this book in an incremental and rather intuitive way. starting from ''the ground-up'' is not always a good idea, and i'm glad this author followed his instincts rather than the herd
the code supplied is working code ( a feat almost unheard of today ), the examination of which helps to illustrate function better than any equivalent volume of text could. in fact the code is so well decomposed in terms of OOP that the text cannot fail to assist even entry-level programmers in the creation of their own parsers using the concepts presented. as for the difficulty of making oneself independent of 'his toolkit', i can only say that more than 95% of the class methods are under ten lines of code ( most are under six ), so it seems that anyone willing to apply themselves should be able to succeed in doing so ; especially considering the fact that his included code covers far more ground than a more sharply focused ( 'real world' ) implementation would ( meaning that, in terms of volume, you would only need to write or implement a tiny fraction of what is included with the book to satisfy any specific implementation )
some reviewers have unambiguously reported putting the concepts presented in this book to work - and quickly - which says a great deal given the perceived complexity of the subject. indeed, creating a parser for a macro assembler for a particular embedded processor was so trivial ( thanks to the concepts in this book ) that i am confident modifying it for other targets will be trivial, as it was modeled after the author's OOP examples. having said that, the OOP perspective this author has provided seems the principal way in which this book is differentiated, making space for itself in an already crowded marketplace
ignorance of the subject matter can be blamed for many of these negative reviews ; some reviewers are so unfamiliar with the subject matter as to call all compiler related concepts 'black-box'. each of the compiler books on my shelf examines a recursive descent parser, but in a far less practical way, and typically in pseudo-code ( including a prominent example claiming to use Java, but instead presenting what i consider to be nothing more than procedural C pseudo-code fragments ). BPWJ follows a preferable route, and anyone who has inordinate difficulty might better fail with a more abstract text on the subject before blaming this author for their own inadequacies
one reviewer complains about the onus of being expected to participate in order to gain comprehension by stating ''To compound it, that code can be a bit perplexing when 95% of his variables have one-letter names -- it just isn't very readable if you're not already familiar with his ideas and approach'', which mystifies me, given that well over 95% of the class methods are under ten lines of code ( most are under six ) ... what kind of neurological damage would account for an inability to retain the type of an identifier within the span of six lines ?
for example :
Token t = new Token();
Assembly a = new Assembly();
String s = "some string given the highly problematic identifier s''
should the time a programmer saves by using OOP be squandered on thinking up unnecessary, lengthy names whose lifespan is less than ten lines ? especially considering that peripheral vision will nearly always encompass the code in question, a scant few lines above ? now ... what was 't' again ???
to round-out his list of disappointments, this same reviewer states ''The good news is that you'll be up and running and writing simple grammars and parsers in very little time. The bad news is that if you're working on anything [...] find yourself forced to peer into the black box to figure what the heck [his code] actually IS doing'', with which i agree - the code included is not geared to any specific project you may have in mind ; rather it is nearly exhaustive so that a working example for you to study is always at hand. warning : you will need to participate if you wish to make use of what you can learn by studying this book. if you are willing to do that, success can be yours ... passively being granted mastery in any area of programming ? i'll take the Vegas odds on that !
another reviewer makes several complaints ... in order : ''(1) ... everything is so dependent on the included framework makes it difficult to learn from. (2) I think the best programming books teach you how to build step-by-step from the ground up. (3) Instead, this book expects you to immerse yourself in the code first''
(1) the code, and related concepts, are examined fully in the text. the code is well designed OOP, rather than a ham-fisted port of procedural code, meaning that anyone with minimal experience in any OO language should be able to write their own, rapidly turning his ''fascinating ideas'' into a coded reality all their own
(2) as for ''learning from the ground up'', the text progresses slowly, beginning with a general overview ( to help readers get their bearings within the overarching conceptual framework being presented ) and moving into actual, albeit initially trivial, examples ( as any good programming book should ) and progresses from that point with chapters focusing on discrete aspects of the subject, as well as considering various implementation domains
(3) good code ( especially *working* code ) helps to illustrate function better than any equivalent volume of text could. having said that, the author forces no one to immerse themselves in code. naturally code is presented - this is a programming book after all, and not a purely theoretical one. the presented code is so well decomposed ( into OO Java ) that the text cannot fail to guide a programmer in the creation of his own parsers using the concepts presented ... so making oneself independent of his 'framework' seems trivial enough, given, again, a minimal competency in nearly any relatively modern OO language. as already indicated, the code is slowly examined initially, and given the brevity of procedures ( mentioned above ) it seems reasonable that anyone willing to apply themselves should be able to master the concepts presented in this book
i cannot abide an above average programming text being trashed by the inexperienced, who might have anticipated possessing ''mad 3l33t haxor skilz'' after flipping through the pages - reviewers reporting having used the material presented in this book tell us more than any failure ever could
warning : anyone who considers studying clear Java code difficult, or is unwilling to expend the effort needed to succeed in learning a new task, should avoid this book and every other book on the subject. perhaps IDG should be made aware of the sales they could expect for a new 'Dummies' title. then these unhappy campers could enjoy cartoons ( ''to spice things up'' ) and be given strained examples, twisted for the sole purpose of setting-up some moronic joke
one note about the code : it was written under an early version of Java ( the book was published in 2001, remember ) and to bring it up to current standards will require hitting the files over the head with a compiler. NetBeans quickly directed me to add annotations, mostly @pragma, which took a few minutes. not a big deal, but now you know
OK, now it's up to you to choose
It's really a excellent book about Parser, and meet my work.
If you really want to create your parser to solve your problem, this is a good start point for you.