Java Reference
In-Depth Information
IN PRACTICE
11.6
Use of the ^ operator for exponentiation is likely to confuse Java pro-
grammers (because it is the bitwise exclusive-or operator). Rewrite the
Evaluator class with ** as the exponentiation operator.
The infix evaluator accepts illegal expressions in which the operators
are misplaced.
a.
11.7
What will 1 2 3 + * be evaluated as?
b.
How can we detect these illegalities?
c.
Modify the Evaluator class to do so.
PROGRAMMING PROJECTS
11.8
Modify the expression evaluator to handle negative input numbers.
For the balanced symbol checker, modify the Tokenizer class by add-
ing a public method that can change the input stream. Then add a
public method to Balance that allows Balance to change the source of
the input stream.
11.9
Implement a complete Java expression evaluator. Handle all Java
operators that can accept constants and make arithmetic sense (e.g.,
do not implement [] ).
11.10
Implement a Java expression evaluator that includes variables. Assume
that there are at most 26 variables—namely, A through Z —and that a
variable can be assigned to by an = operator of low precedence.
11.11
Write a program that reads an infix expression and generates a postfix
expression.
11.12
Write a program that reads a postfix expression and generates an infix
expression.
11.13
references
The infix to postfix algorithm ( operator precedence parsing ) was first
described in [3]. Two good books on compiler construction are [1] and [2].
A. V. Aho, M. Lam, R. Sethi, and J. D. Ullman, Compilers: Principles,
Techniques, and Tools, 2nd ed., Addison-Wesley, Reading, MA, 2007.
1.
C. N. Fischer and R. J. LeBlanc, Crafting a Compiler with C, Benjamin
Cummings, Redwood City, CA, 1991.
2.
R. W. Floyd, “Syntactic Analysis and Operator Precedence,” Journal of
the ACM 10:3 (1963), 316-333.
3.
 
Search WWH ::




Custom Search