CS471 Programming Language Structure I Spring 1999

Homework 1

  1. The two grammars G1 and G2, written in BNF form below, differ in the parse trees generated from the same input sentence. Show, using three simple sentences, how these differences might be reflected in the order of evaluation of sub-expressions.
  2. Rewrite grammar G1 in EBNF form, by replacing all possible recursions by repetitions, and using grouping and optional forms as appropriate.
  3. Redraw your EBNF grammar in syntax diagram form.

Grammar G1:

<expr> ::= <expr-1>
| <expr> + <expr-1>
| <expr> - <expr-1>

<expr-1> ::= <expr-2>
| <expr-1> * <expr-2>
| <expr-1> / <expr-2>

<expr-2> ::= id
| - <expr-2>
| <expr-3>

<expr-3> ::= <id> ** <expr-2>

 

Grammar G2:

<expr> ::= <expr-1>
| <expr-1> + <expr>
| <expr-1> - <expr>

<expr-1> ::= <expr-2>
| <expr-2> * <expr-1>
| <expr-2> / <expr-1>

<expr-2> ::= <expr-2> ** <expr-3>
| <expr-3>

<expr-3> ::= <id>
| - <id>

 

Assignment due: Wednesday, February 10th., in class.