Java Reference
In-Depth Information
chapter
11
compilers
S
tacks are used extensively in compilers. In this chapter we present two
simple components of a compiler: a balanced symbol checker and a simple
calculator. We do so to show simple algorithms that use stacks and to show
how the Collections API classes described in Chapter 6 are used.
In this chapter, we show
How to use a stack to check for balanced symbols
n
How to use a
state machine
to parse symbols in a balanced symbol
program
n
How to use
operator precedence parsing
to evaluate infix expressions
in a simple calculator program
n
balanced-symbol checker
11.1
As discussed in Section 6.6, compilers check your programs for syntax errors.
Frequently, however, a lack of one symbol (such as a missing
*/
comment
ender or
}
) can cause the compiler to produce numerous lines of diagnostics
without identifying the real error. A useful tool to help debug compiler error
Search WWH ::
Custom Search