Java Reference
In-Depth Information
9
Semantic Analysis
9.1 Semantic Analysis for Control Structures
Control structures are an essential component of all programming languages.
With control structures a programmer can combine individual statements and
expressions to form an unlimited number of specialized program constructs.
Some languages constructs, such as the if, switch,andcase statements,
provide for conditional execution of selected statements. Others, such as
while, do,andfor loops, provide for iteration (or repetition) of the body of a
looping construct. Still other statements, such as the break, continue, throw,
return,andgoto statements force program execution to depart from normal
sequential execution of statements.
The exact form of control structures di
ff
ers in various programming lan-
,andJava TM , if statements do not use
a then keyword; in Pascal, ML, Ada, and many other languages, then is
required.
Minor syntactic di
guages. For example, in C, C
++
,C
erences are unimportant when semantic analysis is
performed by a compiler. We can ignore syntactic di
ff
erences by analyzing an
abstract syntax tree (Section 7.4 on page 250). Recall that an abstract syntax
tree (AST) represents the essential structure of a construct while hiding minor
variations in source level representation. Using an AST, we can discuss the
semantic analysis of fundamental constructs such as conditional and looping
ff
343
 
 
 
Search WWH ::




Custom Search