|
![]() |
|
||||
|
|
||||||
Due: Monday, 24 March, beginning of class.
Consider the grammar given at the bottom of this page for the language SPoc (Simple Procedural languge). You are to modify the grammar so that it can be used to develop a top-down parser for SPoc. In particular, it must meet the following requirements:
while [ <boolean_expr> ] { <expr> }
| SPoc grammar | ||
| <SPoc> | ::= | program beginD <decl> endD <SPoc_stmt_list> end |
| <SPoc_stmt_list> | ::= | <SPoc_stmt_list> <SPoc_stmt> |
| <SPoc_stmt_list> | ::= | <SPoc_stmt> |
| <SPoc_stmt> | ::= | <assign> $ |
| <SPoc_stmt> | ::= | if <boolean_expr> then <SPoc_stmt> else <SPoc_stmt> $ |
| <SPoc_stmt> | ::= | if <boolean_expr> then <SPoc_stmt> $ |
| <decl> | ::= | <id_list> |
| <id_list> | ::= | <id_list> <type> <id> |
| <id_list> | ::= | <type> <id> |
| <type> | ::= | int | float |
| <assign> | ::= | <id> = <arith_expr>
|
| <boolean_expr> | ::= | <id> <bool_op> <id> |
| <bool_op> | ::= | = | > | < | != |
| <arith_expr> | ::= | <arith_expr> <arith_op> <arith_expr> |
| <arith_expr> | ::= | <id> | <number> |
| <arith_op> | ::= | + | - | * | / |
| <number> | ::= | <int> | <float> |
| <int> | ::= | <int> <digit> | <digit> |
| <float> | ::= | <int> . <int> |
| <id> | ::= | <id> <char> | <char> |
| <digit> | ::= | 0| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| <char> | ::= | a | b | c | i | j | x | y | z |
|
|
|
Last updated on
15 Mar 2008
by
John
Barr
|