

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!


Large cs3723 Homework # 3 , Due: 2 pm, 2 / 19 / 08 Note: If you collaborated your classmates or used their notes, please note which classmates you collaborated. If you use an external source, besides the text book, lectures, notes provided by the instructor, and your own intellect, please cite that source. Use quote marks if you are quoting material word-for-word from any source (including the text book).
V. Formal Languages / BNF / Parsing (Section 4. 1 , Lecture 2 / 12 )
Order the following types of langauges/grammars according to the Chomsky Hierarchy: context-free, context- sensitive, recursively enumerable, and regular. That is, rank them from most general (most difficult to parse) to least general (easiest to parse).
Which of these type of languages from the Chomsky hierarchy do BNF grammars describe?
What does it say about a grammar if there it can produce a sentence which has more than one parse tree with that grammar?
Consider the BNF grammar for arithmetic expressions: < expr > ::= < expr > + < expr > | < expr > − < expr > | < expr > × < expr > | (< expr >) |
Give a derivation showing how to produce each of the following expressions from
Draw a parse tree showing how to produce each of the following sentences from the non-terminal
Is there more than one parse tree showing how to produce each of the following sentences for the non-terminal
What are lex and yacc? How are they different?
Consider the following BNF grammar for lambda terms:^1 < term > ::= | < term > < term > | λ . < term > | ( < term >) ::= x | y | z |...
Give two derivations showing how to produce each of the following sentences from the non-terminal
Draw a parse tree showing how to produce each of the following sentences from the non-terminal
Is there more than one parse tree showing how to produce each of the following sentences for the non-terminal
(^1) for comparision (cf.), see the grammar on Mithcell page 59
VI. Compilation and Interpretation (Section 4. 1 , Lecture 2 / 14 , R 5 RS)
What is the name of the process by which a program written in some programming langauge is translated into instructions for some hardware machine?
What kind of program executes another program ‘P’ written in some programming language ‘’L’ by simulting ‘L’ and directly performing the tasks required by the statements in ‘P’ as it executes those statements?
What advantages does compilation have over interpretation? What advantages does interpretation have over compi- lation?
Which is usually faster, the interpretation of some program directly or the direct execution of machine code compiled from it?
Why is it a bit of a misnomer to say that a language is an ‘interpreted’ rather than a ‘compiled’ language? Explain more precisely what is meant when someone says X is an interpreted language.
What is a virtual machine (in the sense of the Java Virtual Machine)? And what role does the just-in-time (JIT) compiler play in the virtual machine?
List six compilation phases that might be found in a typical optimizing compiler. Pick one and briefly describe what happens during that phase.
List three optimizations that can be applied during compilation. Briefly explain what one of them does.
The interactive prompt (like in the bottom pane of Dr. Scheme) for Lisp is traditionally defined using a read-eval- print loop (REPL): (loop (print (eval (read)))) What does the eval function in Scheme/Lisp do?
Extra Credit
In Homework # 1 , you were asked to explain how to build a Halt program that takes a program P and and input I and determines whether P halts on I using a magical Halt 0 routine that can determine whether an input-less program halts. (The answer to this question, by the way, is basically giving a proof by contradiction that Halt 0 , like Halt, is undecidable.) The solution was to have Halt rewrite P so that the input is hard-coded. Write a Scheme function H. H should take two list parameters: ( 1 ) a list P representing a Scheme expression that requires input and ( 2 ) and a list I that should be the input for P. H should reuturn a new list P′. P′^ should represent an expression that does not require input but will halt if and only if P would have halted if it was given the input I. You may assume the program P is of the form: ( let (... ( input ( read )).. .) (.. .))) where (read) is a function that reads in input, parses it into a list and returns that list. You may wish to use eval to test your function H by evaluating P′.
In class, we discussed how the fixed-point combinator Y can be used to build a recursive function. It was also men- tioned that the fixed-point combinator Y will not work if translated directly into Lisp/Scheme, because Lisp/Scheme will evaluate the parts of the expression in the wrong order and never terminate. There is, however, a variant of Y , called the call-by-value (or applicative-order) fixed-point operator: Z ≡ λ f .( λ x. f ( λ y.(xx)y))( λ x. f ( λ y.(xx)y)). This can be translated to Scheme as: (define Z (lambda (f) ((lambda (x) (f (lambda (y) ((x x) y)))) (lambda (x) (f (lambda (y) ((x x) y))))))) Define a non-recursive Scheme function F , such that when Z is applied to F , the result will be a recursive function. And that this recursive function, when applied to some number n, results in the nth^ number in the Fibonacci sequence. For example: ((Z F) 0) ⇒ 0 ((Z F) 1) ⇒ 1 ((Z F) 2) ⇒ 1 ((Z F) 8) ⇒ 21 Now, this isn’t a practical use of higher-order functions, since it is much simpler to just use define or letrec so that the recursive function can simply call itself. But it does demonstrate how powerful higher-order functions are, in that they even subsume recursion.