


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Name: Answer all seven questions.
Give a regular expression for each of the following languages over Σ = { 0 , 1 ,... , 9 }.
Prove that the following grammar is ambiguous.
E -> E or E | E and E | not E | ( E ) | x
What is dynamic binding? Give a example in Java or any other OOP language to illustrate it.
Implement a class in C++ or Java named MyCollection that extends a collection class such as the vector or the linked list class. This new class overrides the method add in the following way: it does nothing if the object to be added already exists in the collection; otherwise it calls the add method in the super class to add the object into the collection. Use o1.equals(o2) to test if two objects o1 and o2 are equal.
In Picat, a binary tree can be represented as a structure in the form t(Value,Left,Right), where Left is the left subtree and Right is the right subtree. An empty tree is represented as the atom void. Consider the following functions:
f1(void) = 0. f1(t(_,Left,Right)) = N => N = f1(Left) + f1(Right) + 1.
f2(void) = []. f2(t(Value,void,void)) = [Value]. f2(t(_,Left,Right)) = L => L = f2(Left) ++ f2(Right).
(a) f1($t(1,void,void)) (b) f1($t(1,t(2,void,void),t(3,void,void))) (c) f2($t(1,void,void)) (d) f2($t(1,t(2,void,void),t(3,void,void)))