Programming and Problem Solving with Java

(やまだぃちぅ) #1

(^44) | Java Syntax and Semantics, Classes, and Objects
To read the diagrams, start at the left and follow the arrows. When you come to a branch,
take any one of the branch paths. A lowercase word is a nonterminal symbol.
The first diagram shows that an identifiercan consist of a letter and, optionally, any number
of letters or digits. The nonterminal symbols letterand digitare then defined to be any one of the
alphabetic or numeric characters. Here, we have eliminated the BNF nonterminal symbols <let-
ter-digit-sequence> and by using arrows in the first syntax diagram to allow a
sequence of consecutive letters or digits.
Syntax diagrams are easier to interpret than BNF definitions, but they still can be difficult to
read. In this book, we introduce another metalanguage, called a syntax template. Syntax
templates show at a glance the form of a Java construct.
One final note: Metalanguages show only how to write instructions that the compiler can
translate. They do not define what those instructions can do (their semantics). Formal languages
for defining the semantics of a programming language exist, but they are beyond the scope of
this text. Throughout this book, we will describe the semantics of Java in English.
identifier
letter
letter
digit
letter
digit
_$ABCDEFGH I JKLMNOPQRSTUVWXYZ
abcde f gh i j
0123456789
k l mnopq r s t uvwx y z

Free download pdf