LALR(1) GRAMMAR
Productions from  2.3: The Syntactic Grammar
19.2
PostfixExpression
 and ultimately to
Expression
 (for a parenthesized expression) or
to
ClassOrInterfaceType
 and then to
ReferenceType
 (for a cast). Therefore, the
productions shown above result in a grammar that is not LALR(1).
The solution is to eliminate the use of the nonterminal
ReferenceType
 in the
definition of
CastExpression
, which requires some reworking of both alternatives
to avoid other ambiguities:
CastExpression:
(
PrimitiveType Dims
opt
 )
UnaryExpression
(
Expression
 )
UnaryExpressionNotPlusMinus
(
Name Dims
 )
UnaryExpressionNotPlusMinus
This allows the parser to reduce
matthew
 to
Expression
 and then leave it there,
delaying the decision as to whether a parenthesized expression or a cast is in
progress. Inappropriate variants such as:
(int[])+3
and:
(matthew+1)baz
must then be weeded out and rejected by a later stage of compiler analysis.
The remaining sections of this chapter constitute a LALR(1) grammar for
Java syntax, in which the five problems described above have been solved.
19.2   Productions from  2.3: The Syntactic Grammar
Goal:
CompilationUnit
439






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