< previous page page_47 next page >

Page 47
(text box continued from previous page)
0047-01.gif
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 boldface word is a terminal symbol, and words not in boldface are nonterminal symbols.
The first diagram shows that a decimal integer consists of a nonzero digit followed, optionally, by one or more digits. The second diagram defines the nonterminal symbol NonzeroDigit to be any one of the positive numeric characters. The third diagram defines Digit to be either 0 or one of the nonzero digits. Using BNF, each nonterminal symbol must be defined separately. Here, we have eliminated the BNF nonterminal symbol DigitSequence by using an arrow in the first syntax diagram to allow a sequence of consecutive digits.
Syntax diagrams are easier to interpret than BNF definitions, but they still can be difficult to read. In this text, we introduce another metalanguage, called a syntax template. Syntax templates show at a glance the form a C++ construct takes.
One final note: Metalanguages only show how to write instructions that the compiler can translate. They do not define what those instructions 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 describe the semantics of C++ in English.

 
< previous page page_47 next page >