CS441

Assignments

HomeWork 2.

Points: 55

1.(30 points) Construct a grammar for while statements of each of the following languages:

JavaScript:

<while_stmt>--->while<boolean-expr> <stmt>

C++ :

< while_stmt>--->while<logic-expr> < stmt>

Prolog :

< while_stmt>--->while<condition> < stmt>

Lisp :

< while_stmt>---><while boolean_expr stmt>

COBOL :

< while_stmt>--->perform<stmt>thru<stmt>

Eiffel :

< while_stmt>--->from<initialization-stmt>until<boolean-condition><stmt>

2.(10 points) Given the following English language grammar for constructing sentences:

< sentence>::<subject> verb> <object>.

Introduce a new start symbol< paragraph> that will allow you to generate any number of sentences. Show how the grammar has to be modified to accomplish this.

Answer:

< paragraph>--> < sentence>|< sentence> <paragraph>

< sentence>--> <subject> <verb> <object>

3.(15 points) Give a BNF definition (do not use EBNF) of a language of balanced parentheses. The only two tokens in the language are ( and ). For example, ()() and ((()))()((()())) are in this language, while (((() is not.

Answer:

S::=< A> <B> <S>|< A> <B>

A::=(< A>| (

B::=)< B>| )

Last Modified: January 26, 2002
Alex Omorodion,