Q1.
Program the predicate for presence (membership), inserting and deleting an element from the sorted binary trees presented in class. The code for membership and insertion was discussed in class.
Q2. Problem 13b and 13c.i in Chapter of the Denotational Semantics book3; In addition to and, or and not,
write lambda calculus functions for nand and nor.
Q3. Eliminate left recursion from the following grammar:
P in Program
K in Block
D in Declaration
C in Command
E in Arithmetic Expression
B in Boolean Expresion
I in Identifier
N in Number
P ::= K.
K ::= begin D; C end
D ::= D ; D | const I = N | var I
C ::= C ; C | I := E | if B then C else C | while B do
C | K
B ::= true | false | E = E | not B
E ::= E + E | E - E | E * E | E / E | I | N
I ::= x | y | z | u | v
N ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Program the resulting grammar as a Definite Clause
Grammar.
Your grammar should produce parse trees for the input
programs.
An example input program:
begin
const x = 8;
var y;
var z;
z := 0;
if x = y + 2 then
z := 5 else z := 3;
while not x = z
do
z := z + 2
end.