In a book chapter about compilers, there's the following grammar definition and example code.
...
statement: whileStatement
| ifStatement
| ... // Other statement possibilities
| '{' statementSequence '}'
whileStatement: 'while' '(' expression ')' statement
ifStatement: ... // Definition of "if"
statementSequence: '' // empty sequence (null)
| statement ';' statementSequence
expression: ... // Definition of "expression"
... // More definitions follow
while (expression) {
statement;
statement;
while (expression) {
while(expression)
statement;
statement;
}
}
How is the code's inner-most while
loop valid without {
}
? It looks to me that the statement definition requires them. Is this a mistake in the book or am I misunderstanding the syntax?
[Edit] My apologies for any ambiguity. Everything typed above is verbatim from the book. The omissions were not my doing.