Not logged in. Login

Quiz 1.

Consider the following three grammars.

  • Grammar B1.
<expr> ::= 0 | 1 | <var> | ( <expr> ) | <expr> OR  <expr> | <expr> AND <expr>
<var>  ::= p | q | r | s | t
  • Grammar B2.
<expr> ::= <term> | <term> OR  <expr> | <term> AND <expr>
<term> ::= 0 | 1 | <var> | ( <expr> )
<var>  ::= p | q | r | s | t
  • Grammar B3.
<expr> ::= <term> | <expr> OR  <term>
<term> ::= <factor> | <factor> AND  <term> 
<factor> ::= 0 | 1 | <var> | ( <expr> )
<var>  ::= p | q | r | s | t

In the following problems, assume that the logic operator OR applied to two arguments has the value 1 if either argument is 1, 0 otherwise, while the logic operator AND has the value 1 if both arguments have the value 1, 0 otherwise.

  1. Given the string "p AND q OR s", draw all the derivation trees that can be produced by each of the grammars.
  2. Which of the grammars is ambiguous?
  3. For each of the nonambiguous grammars, explain the precedence and associativity of the logical operators.
Updated Mon Sept. 21 2015, 20:31 by cameron.