
Building Parsers With Java
by Steven John MetskerISBN-10: 0201719622
ISBN-13: 9780201719628
Pub. Date: 03/26/2001
Publisher: Addison-Wesley
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
Overview
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 today's 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 to create new computer languages with XML
- How to translate the design of a language into code
- How to accept an arithmetic formula and compute its result
- How to accept and apply matching expressions like th* one
- How to use tokenizers to define a parser in terms of logical nuggets instead of individual characters
- How to build parsers for a custom logic language like Prolog
- How to build parsers for a custom query language that goes beyond SQL
- How to construct an imperative language that translates text into commands that direct a sequence of actions
0201719622B04062001
Product Details
- ISBN-13:
- 9780201719628
- Publisher:
- Addison-Wesley
- Publication date:
- 03/26/2001
- Edition description:
- BK&CD-ROM
- Pages:
- 400
- Product dimensions:
- 7.30(w) x 9.00(h) x 1.10(d)
Table of Contents
(NOTE: Each chapter concludes with a Summary.)Foreword.
Preface.
Who Should Read This Book.
Using the Toolkit Code and the Sample Code.
Contents of the CD.
Applying the Code on the CD.
Hello World.
Coding Style.
Related Books.
Theoretical Context.
Yacc and Lex and Bison and Flex.
About the Cover.
Acknowledgments.
1. Introduction.
The Role of Parsers.
What Is a Language?
The Organization of This Book.
2. The Elements of a Parser.
What Is a Parser?
Parser Collaborations.
Assemblies.
The Assembly Class Interfaces.
Token and Character Assemblies.
Tokenizing.
Default and Custom Tokenization.
Assembly Appearance.
Assembly Summary.
The Parser Hierarchy.
The Composition of a Parser.
Terminal Parsers.
Using Terminals.
Word Terminals.
Num Terminals.
Literals.
Caseless Literals.
Symbols.
Quoted Strings.
Composite Parsers.
Repetition.
Alternation and Sequence.
Composing a Parser.
The Empty Parser.
Parser Summary.
Assemblers.
Parsers Use Assemblers.
Assemblers Work On Assemblies.
Elements Above.
3. Building a Parser.
Design Overview.
Deciding to Tokenize.
Designing Assemblers.
The Collaboration of Parsers, Assemblers, and Assemblies.
Using an Assembly's Stack.
Assemblers Plug In to Parser Composites.
A Language to Plug In To: Minimath.
Calculating a Minimath Result.
The Minimath Parser as an Object.
Building a Target.
Making a Target Cloneable.
Grammars: A Shorthand for Parsers.
Standard Grammar Shorthand.
Top-Down Grammar Design.
Example: Designing a Grammar for a Track Robot.
A Track Robot Grammar.
Checking for Left Recursion and Cycles.
Translating a Grammar to Code.
Translate Quoted Strings.
Translate Sequences.
Translate Alternations.
Translate Terminals.
Create a Subparser for Each Rule.
Option 1: Declare Each Subparser.
Option 2: Arrange Subparsers as Methods.
Add a Start Method.
Completing a Parser.
Control Pushing.
Design the Target.
Plug In Assemblers.
4. Testing a Parser.
Feature Testing.
Random Testing.
Ambiguity Testing.
Terminal Ambiguity.
Special Tokenizers and Targets.
5. Parsing Data Languages.
The Role of Data Languages.
A Data Language Example.
A Coffee Grammar.
A Tokenizing Problem.
Coffee Assemblers.
Coffee Assembler Code.
Translating the Coffee Grammar to Code.
Data Language Parser Summary.
Parsers with XML.
A Brief History of XML.
The Evolution of XML.
An XML Example.
Helpers.
ShowCoffeeXML.
6. Transforming a Grammar.
The Role of Grammar Transformation.
Ensuring Correct Associativity.
Eliminating Left Recursion.
An Algorithm.
Ensuring Proper Precedence.
Eliminating Parser Class Loops.
7. Parsing Arithmetic.
Building an Arithmetic Parser.
Conventional Symbols.
Conventional Precedence.
Conventional Associativity.
An Arithmetic Grammar.
Arithmetic Assemblers.
Assembler Code.
An Arithmetic Grammar Parser.
8. Parsing Regular Expressions.
The Role of Regular Expressions.
Building a Regular Expression Parser.
A Regular Expression Grammar.
Regular Expression Assemblers.
Assembler Code.
A Regular Expression Parser.
9. Advanced Tokenizing.
The Role of a Tokenizer.
Acquiring a Tokenizer.
Tokenizers in Standard Java.
A Token Class.
A Tokenizer Class.
Tokenizer Lookup Tables.
Tokenizer States.
QuoteState.
NumberState.
SlashState.
SymbolState.
WhitespaceState.
WordState.
Setting a Tokenizer's Source.
Customizing a Tokenizer.
The TokenStringSource Utility.
Customizing a State.
Changing Which State the Tokenizer Enters.
Adding a State.
Token Strings.
10. Matching Mechanics.
Introduction.
Parser Matching.
Repetition Matching.
Collection Parsers.
Sequence Matching.
Alternation Matching.
Empty Matching.
Terminal Matching.
Token Terminals.
Character Terminals.
Terminals Summary.
Parser Matching Utilities.
11. Extending the Parser Toolkit.
The Role of New Types of Parsers.
New Terminals.
New Token Types.
New Parser Features.
An Error-Handling Parser.
Tracks in Action.
12. Engines.
Engines versus Interpreters.
The Role of Engines.
Building Blocks.
Structures.
Variables.
Unification.
Facts.
Programs and Queries.
Proofs.
Backtracking.
Rules.
Additional Features of the Engine.
Comparisons.
Arithmetic.
Evaluation.
Not.
Anonymous Variables.
Lists.
13. Logic Programming.
The Role of Logic Languages.
Building Blocks.
Structures.
Variables.
A Logikus Interactive Development Environment.
Unification.
Comparisons.
Rules, Axioms, and Programs.
Proofs.
Variable Scope.
Variable Joins.
Backtracking.
Looping and Halting.
Gateways.
Additional Features of Logikus.
Comments.
Evaluations.
Negation.
Not Dangerous.
Anonymous Variables.
Lists.
Dot Notation.
List Applications.
Member.
Prefix.
Suffix.
Permutation.
Modeling Transitive and Symmetric Relations.
Symmetric Relations.
Example Applications.
An Authorization Program.
Epidemic.
Generate and Test.
Generate and Test in Java.
Altitude Bands.
14. Parsing a Logic Language.
Building a Logic Language Environment.
A Logikus Grammar.
Comments in Logikus.
Logikus Programs.
Logikus Assemblers.
The Logikus Interactive Development Environment.
A Facade for Logikus.
15. Parsing a Query Language.
The Role of Query Languages.
A Sample Database.
Facts, Objects, and Rows.
Jaql.
Jaql Syntax.
Jaql Joins.
Jaql Expressions.
Building a Query Language Environment.
Translating User Queries to Engine Queries.
Natural Joins.
Where Clauses.
Projection.
A Query Builder.
A Speller.
Jaql Grammar.
Creating the Jaql Parser.
Jaql Assemblers.
The Jaql User Environment.
Exception Handling.
Tracks.
Handling Abject Failure.
16. Parsing an Imperative Language.
The Role of Imperative Languages.
Sling.
Sling Programming.
A Basic Sling.
Adding Slings.
Plotting Time.
Line Effects.
Adding Lines.
Cartesian Plots.
Cartesians as Points.
Polar Plots.
For Loops.
Sliders.
A Composite Example.
More Plots.
The Elements of Sling
Building the Sling Environment.
Building Commands.
A Command Example.
AssignmentCommand.
CommandSequence.
ForCommand.
IfCommand.
NullCommand.
PrintlnCommand.
ReadCommand.
WhileCommand.
Commands Summary.
Sling Commands.
AddFunctionCommand.
AssignFunctionCommand.
Building Runtime Functions.
Function Wrapping.
Umbrella Types.
Runtime Functions in Sling.
Execution Phases.
Prototyping.
Function Evaluation.
Sling Functions.
SlingFunction.
Abs, Ceil, Cos, Floor, Sin, and Tan.
Arithmetic.
Cartesian.
Point.
Polar.
Random.
Scale.
Sling.
Slider.
T.
Variable.
Sling Target.
A Sling Grammar.
Sling Assemblers.
AssignmentAssembler.
ForAssembler.
FunctionAssembler.
NegativeAssembler.
NumAssembler.
PiAssembler.
PlotAssembler.
ScaleAssembler.
SliderAssembler.
VariableAssembler.
A Sling Parser.
Reserved Words.
Assembler Placement.
17. Directions.
Get Started.
Get the Most Out of This Book.
Other Essential Reading.
Keep Going.
Create New Languages for Your Colleagues.
Create New Languages for Children.
Explore Languages as Human Interfaces.
Improve Languages as Receptacles for Human Thought.
Choose Your Own Direction.
Appendix A: UML Twice Distilled.
Classes.
Class Relationships.
Interfaces.
Objects.
References.
Index.
Customer Reviews
Average Review:
Most Helpful Customer Reviews
![]() |
After I read this book three times and wrote a lot of notes and definitions, I learned a good bit from it. The presentation is just not good. It needs a glossary and I don't know what else before it will be a really useful book and an aid to learning. Also, realize that the book is actually intended to help you write your own languages, not to parse existing documents. It's kinda the 'Ask him what time it is and he tells you how to build a watch' situation. I wanted simple instructions on using Java to do parsing and got heavy instruction on parsing, with little review, summary, or restatement.
|
![]() |
I was faced with writing a psuedo-sql type of workflow language. I had thumbed through this book before that and when this part of the project came up, I knew it would help. Parsing, overall, can be a pretty tough problem. This book, however, made it easier than if I was to just try and tackle the problem on my own via various research on the web (I did try that to no avail). I also liked the license that came with the book since I was able to use it in my project without any worries - an added bonus! For anyone wanting to get into parsing, this book not only makes it easy, but provides you a FREE foundation. What more could you want?
|
![]() |
As the author, I can tell you that the objective of this book is to encourage and empower you to create new computer languages. This book pursues this goal in spite of the fact that hundreds of vital computer languages are alive today, many having displaced their ancestors. New and important languages are always on the horizon--You probably encounter and learn new languages every year. And yet, none of these languages is ideal for every application. The variety of thriving languages exists because no language is the perfect fit for every application. In every domain where computer programs run, there is an opportunity for you to bridge the gap between humans and computers. Humans work with text, and computers work with objects. By learning to write parsers, you learn to bridge the gap between computers and the users of your language. You can nestle a new language into any niche, defining how your users interact with computers using text.
|