19.1.5
Problem #5: Cast versus Parenthesized Expression
LALR(1) GRAMMAR
class Problem4 { Problem4() { peter[
When the parser is considering the token
peter
, with one token lookahead to
symbol
[
, it cannot yet tell whether
peter
 will be part of a type name, as in:
peter[] team;
or part of an array access, as in:
peter[3] = 12;
Therefore, after the parser reduces
peter
 to the nonterminal
Name
, it cannot tell
with only one token lookahead whether
Name
 should be reduced ultimately to
Type
 (for an array type) or left alone (for an array access). Therefore, the produc 
tions shown above result in a grammar that is not LALR(1).
The solution is to have separate alternatives for
ArrayType
:
ArrayType:
PrimitiveType
 [ ]
Name
 [ ]
ArrayType
 [ ]
This allows the parser to reduce
peter
 to
Name
 and then leave it as is, delaying
the decision as to whether an array type or array access is in progress.
19.1.5   Problem #5: Cast versus Parenthesized Expression
Consider the production:
CastExpression:
(
PrimitiveType
 )
UnaryExpression
(
ReferenceType
 )
UnaryExpressionNotPlusMinus
Now consider the partial input:
class Problem5 { Problem5() { super((matthew)
When the parser is considering the token
matthew
, with one token lookahead to
symbol
)
, it cannot yet tell whether
(matthew)
 will be a parenthesized expres 
sion, as in:
super((matthew), 9);
or a cast, as in:
super((matthew)baz, 9);
Therefore, after the parser reduces
matthew
 to the nonterminal
Name
, it cannot
tell with only one token lookahead whether
Name
 should be further reduced to
438






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved