Docsity

Programming Languages Final Exam Questions, Study notes of Programming Languages

Toggle sidebar
bg1
Programming Languages
Final Exam
Name:
Answer all seven questions.
Question 1
Give a regular expression for each of the following languages over Σ = {0,1,...,9}.
1. All 5-digit positive integers.
2. All positive integers that begin with 9 and are multiples of 5.
3. All strings that begin with 9 and contain three consecutive 1’s.
Question 2
Prove that the following grammar is ambiguous.
E ->EorE|EandE|notE|(E)|x
1
pf3
pf4

Partial preview of the text

Download Programming Languages Final Exam Questions and more Study notes Programming Languages in PDF only on Docsity!

Programming Languages

Final Exam

Name: Answer all seven questions.

Question 1

Give a regular expression for each of the following languages over Σ = { 0 , 1 ,... , 9 }.

  1. All 5-digit positive integers.
  2. All positive integers that begin with 9 and are multiples of 5.
  3. All strings that begin with 9 and contain three consecutive 1’s.

Question 2

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.

Question 4

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).

  1. What is the result of each of the following function calls?

(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)))

  1. Rewrite f1 and f2 to make them tail-recursive.