4 Assume that a language describes a statement-sequence as a sequence of one or more statements
separated by semicolons (assume statements are defined elsewhere), but with no punctuation at the end of
the statement-sequence. Write the EBNF production.
statement-sequence ?† statement { ; statement }
4.5 Given the following grammar:
expr ?† term + expr | term
term ?† factor * term | factor
factor ?† ( expr ) | number
number ?† number digit | digit
digit ?† 0|1|2|3|4|5|6|7|8|9
188 ANSWERS TO REVIEW QUESTIONS
Draw the full parse tree for the expression:
2 * (3 + 5) + (6 + 8)
term + expr
2*(3+5) 6+8
factor * term term + expr
number factor factor term
digit (expr) number factor
2 (3+5) digit number
6 digit
term + expr 8
factor term
number factor
digit number
3 digit
5
Abstract parse tree on next page . . .
+
/ \
/ \
/ \
/ \
* +
/ \ / \
/ \ / \
/ \ / \
2 + 6 8
/ \
/ \
3 5
4.6 Describe the form in which a program is passed from
a the scanner to the parser.
stream of tokens
b the parser to the semantic analyzer.
parse tree
4.7 Here is a context-free grammar in BNF form:
expr --> expr + term | expr - term | term
term --> term * factor | term / factor | factor
factor --> ex ** factor | ex
ex --> ( expr ) | id
Rewrite this grammar in EBNF form.
Pages:
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507