DOC PREVIEW
UF COP 5555 - Practice Final Questions

This preview shows page 1-2-14-15-29-30 out of 30 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

COP-5555 Programming Language PrinciplesPractice Final QuestionsPROBLEM 1.Add procedures to the denotational description of Tiny. Don’tpanic. Wewill considerprocedures with no parameters, and with no local variables, but the procedures are recur-sive.Two new constructs need to be handled: a procedure declaration, and a procedurecall.Complete the following:CC[<proc I C>] =CC[<call I>] =Hints:1) The solutions are one-liners.2) Treat the procedure declaration as an asignment to the procedure name I.-2-PROBLEM 2.Drawadisplay of the run-time environment, at the point marked "HERE" in the codeshown below, for each of the following twotechniques:1) Static Links.2) Displays.program main;procedure A;begin {A}...end;procedure B(procedure E);varx:integer;procedure C;begin {C}x:=5;<----------- HERE !end;begin {B}E;B(C);end;begin {main}B(A)end;-3-PROBLEM 3.Define each of the following terms; using examples to illustrate them. DynamicType Binding, Operator Overloading, Dangling Pointer,Dynamic Scoping, ActivationRecord, Information Hiding, Object-Oriented Programming Language.-4-PROBLEM 4.On the next twopages are twocopies of the AST for a small Tinyprogram. Place next toeach tree node the necessary attributes. For most nodes, this means four inheritedattributes (on the node’sleft), and fivesynthesized attributes (on the right). Fill in theactual values of ALL the attributes, according to the attribute grammar in your classnotes, i.e. showthe result of propagating the values through the functional graph. DONOTdepict the functional graph itself. Please adher to the convention adopted in class:the attributes are, from left to right: code, error,next, top, type.Note: The first copyofthe tree is for you to scratch up; the second is there in case youwish to produce a final clean copy.-5-program<id:teeny> ; <id:teency>assignif<id:x> read=assignprint<id:x> <int:1><id:x> <int:0><id:x>-6-program<id:teeny> ; <id:teency>assignif<id:x> read=assignprint<id:x> <int:1><id:x> <int:0><id:x>-7-PROBLEM 5.Add the Algol ’for’ loop to the the denotational description of Tiny. The Algol forloop has the following syntax:Statement -> ’for’ ’<identifier>’ ’:=’ List ’do’ Statement => ’for’List -> IntExp list ’,’IntExp -> Expression ’..’Expression => ’..’-> ExpressionForexample:for i:= 0, 8, 9, 8..19, 7..3 do output(i)Note: ranges are intended to count ’upwards’ only.Complete the following:CC[<’for’ <id:x> IE1...IEnC>] =-8-PROBLEM 6.Write an attribute grammar for Roman numerals. In case you don’tremember howroman numerals work, the following rules should refresh your memory:1) Roman numerals are composed of symbols I (one), V (five), X (ten), L(fifty), C (one hundred), D (fivehundred), and M (one thousand).2) A smaller number placed in front of a larger number is subtracted from it.(e.g. IV means four). Only one such smaller number can be subtracted at atime (e.g. IIV does not mean 3).3) A number placed after a greater or equal number is added to it (e.g. DCmeans 600, XIII means 13, and MMM means 3000).BelowisanAST grammar for roman numerals.R → <’roman’ R E >→ ’end’E → <’+’ E E >→ <’-’ E E >→ ’M’ # 1000→ ’D’ # 500→ ’C’ # 100→ ’L’#50→ ’X’ # 10→ ’V’ # 5→ ’I’ # 1Belowisasample AST,produced from the input string ’LIV , CMI’. Note that there aretwo roman numerals: 50+(5-1)=54, and (1000-100)+1=901. Notice the reversed order ofthe subtraction.roman____/ \____/\roman +/\ /\end + -I/\ /\L- CM/\IVThe ultimate goal is produce one attribute, a ’file’ attribute, which will contain the valuesof all the roman numerals in the tree. Determine the following: ATT (attributes), SATT(synthesized attributes), IATT (inherited attributes).Determine the attributes that are attached to each tree node, by specifying the func-tions S and I, as in the class notes. Then write the complete attribute grammar.-9-PROBLEM 7.Showthat the fixed-point finder Y=F. (f. f f)(g. F(g g)) is a fixed-point of thefunction H =y.f. f(y f).-10-PROBLEM 8.Suppose that you are givenanAST and its standardized version ST.a) Is it possible to uniquely destandardize the ST,and reproduce the AST? If so thenwrite a destandardizer in pseudocode format for destandardizing a lambda expres-sion to an RPAL AST.Ifitcan’tbedone, explain whynot.b) Is it possible to uniquely deparse the AST,and produce the RPAL source ? If not,explain whynot. If it can be done, discuss a strategy for producing the RPALsource. Illustrate it with pseudo-code if appropriate.-11-PROBLEM 9.Describe the addition of the ‘‘loop--while’’construct to your Tinycompiler.Describe thechanges you would maketoyour parser by giving the pseudo-code of the relevant portionof your recursive descent parser.Showpseudo-code describing howyour constrainerwould analyze this construct, and showpseudo-code describing howyour code generatorwould generate code for it.The ‘‘loop--while’’construct has the following form:loop S while B : T repeatBoth S and T are statement; B is a boolean expression. S is executed at least once. Aftereach execution of S, expression B is tested: if true, T and then S are executed, and B isexamined again; if false, the iteration stops.-12-PROBLEM 10.What is the output of the following RPAL program ? Explain the program’sbehav-ior in general. Hints: try the Is_Element function first; then the mystery function F.Allthe variable names are intended to be descriptive.let Is_Element Number Tuple = Rec_Is_Element Number Tuple (Order Tuple)where rec Rec_Is_Element Number Tuple Index=Indexeq0->false|(Tuple Index) eq Number -> true|Rec_Is_Element Number Tuple (Index-1)inlet rec Rec_F Tuple Index=Indexeq0->nil|(let Result = Rec_F Tuple (Index-1) in(Is_Element (Tuple Index) Result -> Result|(Result aug (Tuple Index))))inlet F Tuple = Rec_F Tuple (Order Tuple)inPrint ( F (1,2,3,2,4,5,4) )-13-PROBLEM 11.Choose, among the twostatements below, the one you believe isclosest to the truth, andcomplete the statement you’ve chosen.1) Attribute grammars are closer to the denotational approach than the opera-tional approach, because . . .2) Attribute grammars are closer to the operational approach than the denota-tional approach, because . . .-14-PROBLEM 12.Suppose we were to change the description of the binop node in the denotationaldescription of the CSE machine to each of the twodescriptions shown below. Ineachcase determine whether the newdescription


View Full Document

UF COP 5555 - Practice Final Questions

Download Practice Final Questions
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Practice Final Questions and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Practice Final Questions 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?