< previous page page_48 next page >

Page 48
Syntax Templates
In this book, we write the syntax rules for C++ using a metalanguage called a syntax template. A syntax template is a generic example of the C++ construct being defined. Graphic conventions show which portions are optional and which can be repeated. A boldface word or symbol is a literal word or symbol in the C++ language. A non-boldface word can be replaced by another template.
Let's look at an example. This template defines a decimal integer in C++:
0048-01.gif
The shading indicates the part of the definition that is optional. The three dots () mean that the preceding symbol or shaded block can be repeated. So a decimal integer in C++ must begin with a nonzero digit and is optionally followed by one or more digits.
Remember that a word not in boldface type can be replaced with another template. These are the templates for NonzeroDigit and Digit:
0048-02.gif
A brace indicates a list of items from which any one can be chosen. So a nonzero digit can be any one of the numeric characters 1 through 9, and a digit can be either the character 0 or a nonzero digit.
Now let's look at the syntax template for the C++ main function:

 
< previous page page_48 next page >