
74 An Introduction to Compiler Construction in a Java World
For this, we need special machinery. Not only must we differentiate between the two
kinds (basic type and reference type) of casts, but we must also distinguish a cast from a
postfix expression that is a parenthesized expression, for example (x).
Consider the Parser code for parsing a simple unary expression:
private JE x p ression s i mple U nar y Exp r e ssi o n () {
int line = s c a n n er . token (). line ();
if ( have ( LNOT )) {
return new JLogi c a lNotO p ( line , unar y E xpre s sion ( ));
} else if ( seeCast ()) {
mustBe ( LPAREN );
boolean is B a sicType = s eeBas i c Type ();
Type t