Rewrite the following BNF grammar using the form of EBNF described on the bottom
ID: 3791327 • Letter: R
Question
Rewrite the following BNF grammar using the form of EBNF described on the bottom half of page 127 in Sebesta.
<import_decl> import <import_list> ;
<import_list> <package_list>
| <package_list> . *
<package_list> <identifier>
| <package_list> . <identifier>
<identifier> a | b | c
Make the resulting grammar as simple as possible, but keep all four of the original nonterminals, which will now be named ImportDecl, ImportList, PackageList, and Identifier. (Note: There are some typographical errors on page 127. See page 3-21 of the course notes for a better description of this form of EBNF.)
Explanation / Answer
<assign> -> import = <import_list>
<import_list> -> <package_list> {(+ | * ) } '.'
<package_list> -> <identifier> {(+ ) | <package_list>
<identifier> -> ( a | b | c )
The same grammer is shown ebnf in which the
<import_list> <package_list>
| <package_list> . * is converted to <import_list> -> <package_list> {(+ | * ) } '.'
and <identifier> a | b | c is converted to <identifier> -> ( a | b | c ) with parenthesis.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.