CS 405 Exam #2: Topics and Sample Questions for Programming Languages Exam, Exams of Programming Languages

An outline of the topics to be covered in exam #2 for the cs 405 programming languages course, along with sample questions. The exam will cover static and dynamic semantics, functional programming languages, and attribute grammar. The questions include fill in the blank, true or false, multiple choice, short answer, and discussion questions.

Typology: Exams

Pre 2010

Uploaded on 04/12/2010

koofers-user-wa8
koofers-user-wa8 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 405 PROGRAMMING LANGUAGES
TOPICS TO BE COVERED ON EXAM #2
October 14, 2003
The exam will cover everything we have discussed from Chapters 3 (i.e. Sections 3.4, 3.5 -
except 3.5.2 and 3.5.3) and 15 (i.e. all sections except 15.7-15.8) in the text and all notes, but
emphasizing the material covered in class. The style of the exam will be very flexible, possibly
consisting of fill in the blank, true or false (possibly with justification), multiple choice, matching,
short answer (e.g. definitions or listing), and discussion questions. You will not be asked to work
detailed problems such as writing any actual code (i.e. code in a specific language like Java or Lisp
- you should be able to write pseudo-code for a recursive descent parser). You should have some
ideas about the theory behind implementation of programming languages (e.g. the relationship
between formal models of computation and programming languages, λ-calculus etc.). Some smaller
problems such as drawing a (small) attributed parse tree or Lisp representation of a list are likely.
A brief outline of the topics we have covered is described below. (This list is intended to be
as complete as possible but may not be all inclusive.)
Programming Languages - Semantics. We discussed static and dynamic semantics and formal
methods to describe them. Attribute grammar was discussed for static semantics (mainly)
and we introduced the three formal methods for dynamic semantics.
Functional Programming Languages. Lambda calculus was introduced as the foundation of
denotational semantics and functional programming. The LISP programming language was
discussed as an example of the functional language paradigm. You should know the general
design philosophy and syntactic and semantic flavor. You do NOT need to know specific
commands in detail, but should know some basic ones (e.g. defun,cond,eq,setq,cons,
car,cdr,append,list). Examples of the most detailed information of a fundamental nature
you should know would be how functions are defined, how lists are represented internally, and
how functions may be manipulated as data.
pf2

Partial preview of the text

Download CS 405 Exam #2: Topics and Sample Questions for Programming Languages Exam and more Exams Programming Languages in PDF only on Docsity!

CS 405 PROGRAMMING LANGUAGES

TOPICS TO BE COVERED ON EXAM

October 14, 2003

The exam will cover everything we have discussed from Chapters 3 (i.e. Sections 3.4, 3.5 - except 3.5.2 and 3.5.3) and 15 (i.e. all sections except 15.7-15.8) in the text and all notes, but emphasizing the material covered in class. The style of the exam will be very flexible, possibly consisting of fill in the blank, true or false (possibly with justification), multiple choice, matching, short answer (e.g. definitions or listing), and discussion questions. You will not be asked to work detailed problems such as writing any actual code (i.e. code in a specific language like Java or Lisp

  • you should be able to write pseudo-code for a recursive descent parser). You should have some ideas about the theory behind implementation of programming languages (e.g. the relationship between formal models of computation and programming languages, λ-calculus etc.). Some smaller problems such as drawing a (small) attributed parse tree or Lisp representation of a list are likely.

A brief outline of the topics we have covered is described below. (This list is intended to be as complete as possible but may not be all inclusive.)

  • Programming Languages - Semantics. We discussed static and dynamic semantics and formal methods to describe them. Attribute grammar was discussed for static semantics (mainly) and we introduced the three formal methods for dynamic semantics.
  • Functional Programming Languages. Lambda calculus was introduced as the foundation of denotational semantics and functional programming. The LISP programming language was discussed as an example of the functional language paradigm. You should know the general design philosophy and syntactic and semantic flavor. You do NOT need to know specific commands in detail, but should know some basic ones (e.g. defun, cond, eq, setq, cons, car, cdr, append, list). Examples of the most detailed information of a fundamental nature you should know would be how functions are defined, how lists are represented internally, and how functions may be manipulated as data.

CS 405 EXAM #2 SAMPLE QUESTIONS

  1. The mathematical model of computation that the Lisp programming language is based upon is called .
  2. True or False. Denotational semantics is a method for defining the semantics of a programming language by giving an interpreter for that language.
  3. Consider the attribute grammar below:

::= <a-n> <b-n> <c-n> <b-n>. count ← <a-n>. count <c-n>. count ← <a-n>. count <a-n> ::= a <a-n>. count ← 1 | <a-n> 1 a <a-n>. count ← <a-n> 1. count + 1 <b-n> ::= b Condition: <b-n>. count = 1 | <b-n> 1 b <b-n> 1. count ← <b-n>. count − 1 <c-n> ::= c Condition: <c-n>. count = 1 | <c-n> 1 c <c-n> 1. count ← <c-n>. count − 1

(a) Indicate which attributes are inherited, which are synthesized, and which are intrinsic. (b) Draw the attributed parse tree for the string “aaabbbccc”, showing clearly the order of evaluation of all attributes.

  1. In pure λ-calculus, integers, Boolean values, lists, etc., must all be represented by λ-expressions. For example, 0 = λx.λy.y, 1 = λx.λy.x y, 2 = λx.λy.x (x y), etc., and succ = λz.λx.λy.x ((z x) y). succ is a function which adds 1 to its argument. Evaluate succ 1. Did you get 2? Why or why not?
  2. Consider the following Lisp function:

(defun update (store V n) (prog (currentenv newbinding newstore) (setq currentenv (cdaddr store))) (setq newbinding (cons (list ’eq ’V (list ’quote V)) (list n))) (setq newstore (list ’lambda (list ’V) (cons ’cond (cons newbinding currentenv)))) (return newstore))))

Note that the (prog (list of local variables) (exp-1) (exp-2) ... (exp-n) (return exp)) construction declares a list of local variables used in the expressions with exp being the value returned. Let S represent the Lisp expression (lambda (V) (cond ((eq V (quote x)) 4) (t (quote bottom)))). What is the internal list representation that Lisp uses for S? What is (cdaddr S)? Trace the execution of (update S ’x 5), showing the values of currentenv, newbinding, and newstore.