Java Reference
In-Depth Information
▪ JParsec lets %%»%%you write the parser in straight Java, so it's all built at compile time
(most of the others require a separate parse generation step, with the build and debugging
issues that that raises). JParsec is moving from Codehaus to GitHub .
JFlex and CUP work together like the original yacc and lex .
▪ Parboiled uses Parsing Expression Grammar (PEG) to also build the parser at compile
time. See GitHub for more information.
Rats! parser generator is part of the eXTensible Compiler Project at New York
University.
▪ There are others; a more complete list is maintained at Java Source .
These “compiler generators” can be used to write grammars for a wide variety of programs,
from simple calculators—such as the one in Scanning Input with the Scanner Class —through
HTML and CORBA/IDL, up to full Java and C/ C++ compilers. Examples of these are in-
cluded with the downloads. Unfortunately, the learning curve for parsers in general precludes
providing a simple and comprehensive example here, let alone to compare them intelligently.
Refer to the documentation and the numerous examples provided with each distribution.
As an alternative to using one of these, you could simply roll your own “recursive descent
parser,” and once you learn how to do so, you may find it's not really that difficult, quite pos-
sibly even less hassle than dealing with the extra parser generator software. (Depending on
the complexity of the grammar involved, obviously.)
Java developers have a range of choices including simple line-at-a-time scanners using
StringTokenizer , fancier token-based scanners using StreamTokenizer , a Scanner class
to scan simple tokens (see Scanning Input with the Scanner Class ) , Regular Expressions (see
Chapter 4 ) , and third-party solutions include grammar-based scanners based on the parsing
tools listed here.
Opening a File by Name
Problem
The Java documentation doesn't have methods for opening files. How do I connect a file-
name on disk with a Reader , Writer , or Stream ?
Search WWH ::




Custom Search