Docsity

Review Sheet Final Exam - Programming Language | CSC 4101, Study notes of Programming Languages

Toggle sidebar
bg1
1
1
Programming Languages
Tevfik Koşar
Lecture - XXVIII
May 4th, 2006
2
Final Exam
• Date: May 11th, Thursday
• Time: 12:30pm – 2:30pm
• Place: 215 TUREAUD HALL
• Final will be comprehensive. It will cover everything we have
learned this semester.
• Final will be open book. You can use your book during the exam,
but no other notes.
• Check the class notes. Anything not covered in the class will not be
asked.
• Expect similar questions to the homework assignments and
quizzes.
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Review Sheet Final Exam - Programming Language | CSC 4101 and more Study notes Programming Languages in PDF only on Docsity!

1

Programming Languages

Tevfik Koşar

Lecture - XXVIII May 4th, 2006

2

Final Exam

  • Date: May 11th, Thursday
  • Time: 12:30pm – 2:30pm
  • Place: 215 TUREAUD HALL
  • Final will be comprehensive. It will cover everything we have learned this semester.
  • Final will be open book. You can use your book during the exam, but no other notes.
  • Check the class notes. Anything not covered in the class will not be asked.
  • Expect similar questions to the homework assignments and quizzes.

3

Hints

  • Be sure that you know:
    • how to write regular expressions
    • how to generate NFA and DFA from regular expressions
    • how to generate parse trees
    • difference between top-down and bottom-up parsing; LL vs LR grammars
    • difference between static vs dynamic scoping
    • how to generate attribute grammars; decorate parse trees; and generate syntax trees
    • expression evaluation orders; applicative vs normal-order evaluation
    • basic scheme functions; lists, searching, and scoping in Scheme

4

Hints (cont.)

  • type equivalence (structural and name equivalence)
  • type inference
  • memory layout for records (structures) and variant records (Unions)
  • basic prolog functions, resolution, unification, lists, and arithmetic.
  • OOP; object initialization, static vs dynamic binding
  • concurrent programming: data parallelism vs function parallelism
  • threads vs processes
  • shared memory: sychronization

7

Finite Automaton

  • Convert the regular expression (01)*1 to a DFA.

1) Convert regular expr to NFA

2) Convert NFA to DFA

3) Optimize

NFA Construction Rules;

  • Concatenation
  • Alternation
  • Kleene Closure

8

Parse Trees

  • Consider the same CFG: Odd  Digits 1 Digits  Digit Digits | ε Digit  0 | 1
  • Show the parse tree for input string 1101
  • Is it ambiguous?

9

Attribute Grammars

  • Consider the same CFG:

Odd  Digits 1

Digits  Digit Digits | ε

Digit  0 | 1

  • Show the attribute grammar which would accumulate

the decimal value of the binary input string into a val

attribute of the root of the pare tree.

10

Attribute Grammars (cont.)

Answer:

Odd  Digits 1 :- Odd.val := Digits.val + 1

Digits  Digit Digits :- Digits1.val := Digit.val*2^(Digits.len)+Digits2.val Digits1.len := Digits2.len + 1

Digits  ε :- Digits.val := 0 Digitslen := 0

Digit  0 :- Digit.val := 0 Digit  1 :- Digit.val := 1

13

Evaluation Order

  • Applicative-order evaluation
    • Evaluate arguments before passing them to subroutine
  • Normal-order evaluation
    • Evaluate them only when it is needed

14

Evaluation Order (cont.)

Consider the following Scheme definition:

>> (define (test x y) (if (= x 3) 1 y))

Write the output of the following call to this

function

>> (test 3 (/ 5 0))

assuming normal-order evaluation is used:

assuming applicative-order evaluation is used:

1

Error: Division by Zero!

15

Basic Scheme Functions

Show the return values of the following

Scheme expressions:

a) (car (cdr `(1 2 3 4)))

b) (cdr (car `(1 2 3 4)))

c) (cons (car (1 2) ) (cdr(3 4)))

d) (car (list (1 2)(3 4)))

e) (cdr (append (1 2)(3 4)))

2 () (1 4) (1 2) (2 3 4)

16

Basic Scheme Functions (cont.)

Write the output of the following Scheme programs:

a) >> (let ((a 2) (b 5) (c 9)) (let* ((a 3) (b a) (c b)) (let ((a 4) (c a) (b c))) (+ a b c)) ) )

b) >> (let ((a 2) (b 5) (c 9)) (let ((a 3) (b a) (c b)) (let* ((a 4) (c a) (b c))) (+ a b c)) ) )

Output: 10 ; 4+3+

Output: 12 ; 4+4+

19

Prolog: Unification

  • Pattern-matching process used to associate variables

with their values

  • student(joe).
  • :- student(X).
  • X = joe;
  • Unification Rules:
  • A constant unifies only with itself
  • Two structures unify iff same functor and same # of arguments, and corresponding arguments unify recursively
  • A variable unifies with anything.

20

Prolog: Unification

?- a = a. yes ?- a = b. no ?- foo(a, b) = foo(a, b). yes ?- X = a. X = a; no ?- foo(a, b) = foo(X b). X=a; No ?- A = B. A = _ B = _

21

Prolog: Lists

  • [a, b, c] can be expressed as (using vertical bar notation):
    • [a | [b, c]]
    • [a, b | [c]]
    • [a, b, c | []]
  • member(X, [X|T]).
  • member(X, [H|T]) :- member(X, T).
  • sorted([]).
  • sorted([X]).
  • sorted([A, B | T]) :- A <= B, sorted([B | T]).

22

Prolog: Lists

append([], A, A). append(H | T), A, [H | L]) :- append(T, A, L).

?- append([a, b, c], [d, e], L). L = [a , b, c, d, e] ?- append(X, [d, e], [a, b, c, d, e]). X = [a, b, c] ?- append([a, b, c], Y, [a, b, c, d, e]). Y = [d, e]

 Prolog predicates do not have a clear distinction between input and output arguments!

25

Concurrency: Function Parallelism

  • a=b+1;
  • a=a+c;
  • a=2*a;
  • d=5*d;
  • e=d-1;
  • e=e+1;
  • g=f*3;
  • f=f-1;
  • f=f*4;

a = b + 1 a = a + c a = 2 * a

a = b + 1 a = a + c a = 2 * a d= 5 * d e = d - e = e + 1

g=f* f=f- f=f*

d= 5 * d e = d - e = e + 1 g=f* f=f- f=f*

TASK 1 uses a,b,c

TASK 2 uses d, e

TASK 3 uses f, g

Decompose COMPUTATIONS into pieces (functions). Data are taken to the tasks where they are needed.