ࡱ>  Nbjbj "jjEl55555lm>7>7>7>7>7>7>7>7lllllll$|o qli>7>7>7>7>7lL>7>7dmLLL>7f>7>7lL>7lLLLeg>727 35; yfgzm0mf^JrVHJrgLbrThings to know for exam on Thursday Note that it is not possible to take a make-up exam Bindings typesWhat are the four types of bindings generally associated with a variable? timesFor each of the following bindings commonly associated with a variable, tell when they most commonly occur (be as specific as possible): location value type name  c. timesWhat type of binding generally occurs at language design time language implementation time compile time load time run timetimes Louden, p. 80 #5.1 2nd editionPick a language from among the languages C, Java, Ada, and Pascal, and give as precise binding times as you can for the following attributes, and give reasons for your answers: the maximum number of significant digits in a real number the meaning of char the size of an array variable the size of an array parameter the location of a local variable the value of a constant the location of a function Variable scope dynamic static Louden, p. 181, #5.9, 2nd edition procedure scope2 is a, b: integer; function p return integer is a : integer; begin - point 1 a := 0; b := 1; return 2; end p; procedure print is begin -- point2 put(a); new_line; put(b); new_line; put(p); new_line; end print; procedure q is b, p : integer; begin point 3 a:= 3; b := 4; p := 5; print; end q; begin a := p; q; end scope2; with ada.text_io; with ada.integer_text_io; use ada.text_io; use ada.integer_text_io; procedure scope1 is a, b: integer; function p return integer is a,p : integer; begin -- point 1 a := 0; b := 1; p := 2; return p; end p; procedure print is begin -- point2 put(a); new_line; put(b); new_line; end print; procedure q is b : integer; begin -- point 3 a:= 3; b := 4; print; end q; begin a := p; q; end scope1;  lifetime  Selection statements in FORTRAN, Java, Pascal, Ada types behavior syntax short circuit evaluationThe basic form of an <if-statement> is shown below in EBNF where <statement> is either a single statement or a group of statements enclosed in curly braces. <if-statement> ! if (<expression>) <statement> [else <statement>] By the above run, the following is a legal in which e1 and e2 are expressions and S1 and S2 are statements or statement groups. if (e1) if (e2) S1 else S2 Either explain in words why this if-statement is ambiguous or draw two different parse trees for The advantage of short-circuit evaluation of Boolean or logical expressions is that it can prevent certain runtime errors from occurring. Describe how short-circuit evaluation behaves with the and operator. Given the following pseudo-code examples, which is the one that can prevent an error from occurring and what error might occur with the other one? if (i <= last index) and a(i) >= x) then .... if (a(i) >= x) and (i <= last index) then ...Given the following legal FORTRAN statements, show how they would be written in Java or Pascal. if (x) 10, 20, 30 10 write (6,22) x * x go to 40 20 write (6, 22) x + 4.5 go to 40 30 write (6, 22) x - 5.3 40 x = x + 2.2The advantage of short-circuit evaluation of Boolean or logical expressions is that it can prevent certain runtime errors from occurring. Describe how short-circuit evaluation behaves with the and operator. Given the following Pascal like pseudo-code examples, which is the one that can prevent an error from occurring and what error might occur with the other one? if ( p <> nil and p^.data = 10) then ... if (p^.data = 10 and p <> nil) then ... The advantage of short-circuit evaluation of Boolean or logical expressions is that it can prevent certain runtime errors from occurring. Describe how short-circuit evaluation behaves with the or operator Given the following Pascal like code where p is a pointer, rewrite the following and statement as an equivalent or statement. if ( p <>= null and p^.data = 10) then this may not be good...C, C++, and Java all require their Boolean operators to be short circuit. Pascal does not, and Ada allows the programmer to choose. How does the Ada programmer distinguish between a statement in which they want short-circuit evaluation to occur and one in which they dont? Show a code example.C, C++, and Java all require their Boolean operators to be short circuit. Pascal does not, and Ada allows the programmer to choose. Given the following Pascal-like pseudo code in a language which has short-circuit evaluation, how would you have to write the code in a language which didnt have it to avoid the error that is prevented in a language which has it? if (p <> nil) and p^.data = 10) then ... (True or False) In Ada, the case values must be distinct as well as exhaustive. Rewrite the ada case statement below, as a Java case statement case x-1 is when 0 => y := 0; z := 2; when 2..5 => y := 3; z := 1; when 7 | 9 => z := 10; when other => null; end case;How would the following FORTRAN statement be written in Pascal? goto (53, 42, 1, 13, 20) X  Iteration statements in FORTRAN, Java, Pascal, Ada types behavior syntaxIn C and Java the index value of a for loop may be defined outside of the for loop or inside it. Where is the index values of an Ada for loop declared? What are three differences between the for loop in Ada and Pascal? What are three differences between the for loop in Ada and Java? The following code would be flagged as illegal by the Ada compiler for i in 1..10 loop i := 5; ada.integer_text_io.put (i); end loop; Why?The following code is legal in Ada. for i in -1 .. 1 loop ada.integer_text_io.put (i); for i in 3..3 loop ada.integer_text_io.put (i); for i in reverse 6..7 loop ada.integer_text_io.put(i); end loop; ada.text_io.new_line; end loop; end loop; What would the output be if it were run? Assuming i is declared previous to this code, what would the output be in the corresponding Java loop? Assuming i is declared previous to this code, what would the output be in the corresponding Pascal loop? How many times would i be output if the following Ada loop was executed? num := 5; for i in 1..num loop ada.integer_text_io.put (i); num := 3; end loop; How many times would i be output if the corresponding Java loop was executed? How many times would i be output if the corresponding Pascal loop was executed?Ada, Java, FORTRAN, and Pascal all have iteration control structures. Choose two (2) forms of iteration control structures in any one (1) of these languages, show their syntax in pseudo code and describe clearly the major difference between them. Subprograms in FORTRAN, Java, Pascal, Ada types parameter modes syntax resultsWhat are two distinct types of subprograms present in all of these languages? What is the major difference between them?How do each of the following languages pass their parameters? FORTRAN Java Pascal What are Adas parameter modesIn FORTRAN IV, a function returns its value by assignment to the function name. What type of function is available in Java, Pascal and Ada that this type of return mechanism prevents?Te following subproram is written in FORTRAN. If this program is called with actual parameters M and N holding 4 and 5 respectively, then after return from the subprogram, M and N will hold 5 and 4 respectively. What parameter mechanism does FORTRAN use that causes this? SUBROUTINE SWAP (K, L) ITEMP = K K = L L = ITEMP RETURN END If this subprogram were written in Java and called with M and N holding 4 and 5 respectively, what would M and N hold after return from the subprogram? What parameter mechanism does Java use that causes this? If this subprogram were written in Pascal, the programmer could choose what M and N would hold after return from the subprogram. Describe how this is accomplished. The following code fragment uses arrays in Java. The first line declares and allocates an array of two integers. the next two lines initialize it. int[ ] A = new int [2] A [ 0] = 0; A[1] = 2; f ( A[0], A[A[0]]); Function f is defined as void f (int x, int y) { x = 1; y = 3; } For each of the following parameter-passing methods, say what the final values in the array A would be after the call to f. by value (i.e. copy) by reference (i.e. address) by result (i.e. copy out) by value-result (i.e. copy in, copy out) by name - not yet page 385 Webber, Modern Programming Languages, ex 6 Briefly explain the following parameter passing mechanisms and the difference between them. For each, tell a language that uses it. parameter passing by value parameter passing by reference parameter passing by result parameter passing by value-result page 101, exercise 15, RoostaWhat is the output of the following program written in Pascal syntax using the following parameter passing mechanisms: pass by value pass by reference pass by result pass by value-result program test (output); var i : integer; a : array [1..2] of integer; procedure P( x,y : integer); begin x := x + 1; i := i + 1; y := y + 1; end; begin a[1] := 1; a[2] := 1; i := 1; P( a[i], a[i]); (* heres the problem line *) writeln (a[1]); writeln (a[2]); end. page 101, exercise 16, Roosta (have some doubts about this one) Grammars components purposes BNF vs EBNF pre-conditions Dr. Groves material limitationsWhat were three (3) of the things that the BNF for Mini-Language Core was not able to specify?What are the component parts of a grammar?What are the two main purposes of a grammar? (i.e. what can we do with one?) Given the following context-free grammar: S ! 0S | 1A A ! 0S | 1B B ! 0S | 1C | 1 C ! 1C | 0C | 1 | 0 Generate 3 valid sentences in this language page 117, example 4.7 RoostaGiven the following grammar G = ( {S,A}, {0,1}, P, S) represented by the following production rules where ! is the empty string which has length 0. S ! 0A1 A ! 0A1 A ! ! Generate 3 valid sentences in this language. Tell in words what the sentences in this language look like. page 118, example 4.9 RoostaAssume the following grammar: < assign > ::= < id > := < expr > < id > ::= A | B | C < expr > ::= < id > + < expr > < expr > ::= < id > * < expr> < expr > ::= (< expr>) < expr> ::= < id > Show a parse tree and a left-most derivation of the following statement: A := A * ( B + ( C * A )) page 136, problem 8, RoostaUsing the following syntactic specifications, demonstrate the ambiguity of the grammar by displaying two derivation tress fo the expression a+b+c ::= | ::= | ::= + | - ::= a|b|c page 137 , problem 15, RoostaConsider the following productions: ::= [ , ] ::= ::= ::= () ::= x ::= y ::= z for each of the following strings, show every step in the derivation tree that proves that the string belongs in the grammar z (x) [y] [(x),y] [ (x), [y,x]] page 137, #13, RoostaProve that the following grammar is ambiguous but first, tell what it means for a grammar to be ambiguous. ::= ::= + ::= ::= a|b|c page 136, problem 9, RoostaAssume that we have the following production rules ::= ::= + ::= - ::= * ::= 40 | 3 | 9 Is the expression 40-3-9 ambiguous? Prove that it is or it isnt page 136, problem 10 RoostaCopnsider the following grammar specifications: ::= * ::= & ::= c Give a derivation and parse tree for the string c*c&c&c*c Prove that the grammar is ambiguous modification of p 138, problem 20, RoostaGiven the following grammar G = ( {S,T}, {a,b}, P, S) represented by the following production rules where ! is the empty string which has length 0. S ! aaTb T ! aaTb T ! ! Generate 3 valid sentences in this language. Tell in words what the sentences in this language look like. variation of page 138, problem 19 , Roosta Exception handling in FORTRAN, Java, Pascal, AdaDescribe the exception handling mechanisms we have seen in two (2) of the following four (4) languages: FORTRAN, Java, Pascal, AdaWhat is the difference in approach to exception handling between Java and Ada?Describe what happens when an exception occurs in Java All of Chapter 1 in our text why study languages how to evaluate languages influences on language design language categories language design trade-offs implementation methodsWhat are three (3) desireable characteristics of a programming language?What do we gain from studying a variety of programming languages?It has been said that languages shape the way we think. With regard to the domain of programming languages, do you agree or disagree with that statement? Explain why you agree or disagree and give examples to illustrate your choice.In order for high level programming languages to be run on computers they must be translated into the machine language of the computer they are running on. What are the two methods of translation we have talked about? Describe the major difference between them. The two common methods of translation from high level programming language to machine language are compilation and interpretation. Tell what methods are used by each of the following languages: FORTRAN Java Pascal Data types in FORTRAN, Java, Pascal, Ada scalar structured type compatibility type checkingDescribe two (2) ways in which FORTRAN differs from Ada with regard to data type What are the scalar types we studied in FORTRAN? What are the scalar types we studied in Pascal? Pascal has a structured data type called a record. FORTRAN IVs only structured data type is an array. Given the following Pascal declaration for an array of records, write the necessary FORTRAN declarations to manipulate the same data. InfoRecord = Record number : integer; earnings, tax : real; end; EmployeeRecords = Array [1..100] of InfoRecordAssuming that X has been declared to be a floating point number and assigned the value 98.7 and that N has been declared to be an integer and assigned the value 25, What is the result of adding X and N and storing the result in N in FORTRAN? Describe what happened and why? What is the result of adding x and n and storing the result in X in Ada? Describe what happened and why.  Dr. Bernsteins material  Chapter 2 in our text on FORTRAN, Java, Pascal and Ada Basic statements typesWhat are the five basic types of statements that we generally expect to find in a programming language. For one (1) of these types of statements, pick two (2) of the languages we have written programs in this semester (FORTRAN, Java, Pascal and Ada) and describe two (2) differences between them.  Miscellaneous DOS compilation commands use of files redirection What is a potential problem that occurs when using DOS redirection to send a programs output to a file? When using files in Pascal, what are the necessary actions that must occur? ( you may either give a series of code statements or describe in words)When using files in Pascal, if you neglect to close the files when you are done with them, what problem may occur?Given the following FORTRAN code and a line of input consisting of the digits shown below with no spaces between them , what would be stored in the variables and what would the output be? 1234567898765432123456789 READ (5, 13) X, Y, I, Z FORMAT (F3.2, 1X, F7.3, I4, F2.1) WRITE (6, 14) X,Y,I,Z FORMAT (1X, F5.2, 2X, F8.3, 1X, I5, 1X, F3.1) 1234567898765432123456789 1.23 5678.987 6543 2.1 Given the following FORTRAN code and a line of input consisting of the digits shown below with no spaces between them , what would be stored in the variables and what would the output be? 1234567898765432123456789 READ (5, 13) X, Y, I, Z 13 FORMAT (F3.2, 1X, F7.3, I4, F2.1) WRITE (6, 14) X,Y,I,Z 14 FORMAT (1X, F5.2, 2X, F7.2, 1X, I5, 1X, F3.1) STOP END 1234567898765432123456789 1.23 5678.99 6543 2.1 Given the following FORTRAN code and a line of input consisting of the digits shown below with no spaces between them , what would be stored in the variables and what would the output be? 1234567898765432123456789 READ (5, 13) X, Y, I, Z 13 FORMAT (F3.2, 1X, F7.3, I4, F2.1) WRITE (6, 14) X,Y,I,Z 14 FORMAT (1X, F5.2, 2X, F7.3, 1X, I5, 1X, F3.1) STOP END 12345678987654321234567898 1.23 ******* 6543 2.1 Chapter 5 textbook slides chcegs   . 2 K N _ b | 4 : D G i r y |   ! & ' 2 i l w } B*OJQJ^J_HXphB*OJQJ^J_HXphB*OJQJ^J_HXph5\ B*H*ph B*phN$%YZci^r$$Ifl0n$hx064 laW$If & FA$If^A & Fq$If^qh^h$a$ NDNU\cdesePr$$Iflh0n$hx064 laW h$If^h $If^$If & F$If^  =\}siiii & F$If & F$Ifr$$Iflh0n$hx064 laW$If h$If^h \} ysmmmh^h$If h$If^hr$$Iflh0n$hx064 laW & F$If  +N ( @ j $If & F$If^ & FA$If^A & Fq$If^q 7 ` p    t$If$If   4 }}4}s}qqq & F$If$If h$If^hr$$Ifl0$hx064 laW @~ & F$If^ & F$If^$If $<]v ?W-:;ELYV#'JN"$*/behjkrx5!."B*^J_HXphB*OJQJ^J_HXphB*OJQJ^J_HXph^J_HXOJQJ B*ph6]OJPJQJo(Lyz=Yux $Ifr$$Ifl0s$0(064 lau{|cd r$$Ifl0s$0(064 la$IfOP?WXl r$$Ifl0s$0(064 la$Iflm rr$$Ifl0s$0(064 la$If!0@LVW|r$$Ifl0s$0(064 la$Ifseee & F$If^ & F$If^h^hr$$Ifl0s$0(064 la$If  !"eyl}}}}}} $If $If^r$$Ifl0s$0(064 la7 B X y 4!$If $If^4!5!."/"0"1"["a"q"x""}{m____ & F$If^ & F$If^$If $If^r$$Ifl0s$0(064 la """""9#A#F#M#N#m#n#*$A%B%}}}}}} $If^r$$Ifl0s$0(064 la$IfB%Y%j%w%%%%%v&w&'''''}} $If^r$$Ifl0s$0(064 la$If'''((!(;(A(P(_(e(f((()/)Y)n)o)))**+*F*e***$If & F $If $If^."b)m)n))**_,},,,..........n//0000000011"1$1&112233R3n34456*63666 8)889:::R:Z:\:r:t::::::r;v;;yBB"JWJKLMMN6]PJ OJPJQJOJPJQJo( B*phO*****;+I+[+j++++++}ssss & F $If $If^r$$Ifl0s$0(064 la$If +++++ ,, ,!,',4,A,K,},,,,,,,$If,,,,,---4-@--}ooooooi$If & F$If^ & F$If^r$$Ifl0s$0(064 la ---2.4.6......//j/l/}}$If $If^r$$Ifl$ 0s@$0(064 lal/n///00 1&1(1111222}X r$$Ifl$ 0s@$0(064 la$If $If^2=2a2y22222263Q3R3n344A4g4}4444$If $If^4444455)565C5P5Q55555p $If^r$$Ifl$ 0s@$0(064 la555556r6s66666666}, r$$Ifl$ 0s@$0(064 la$If $If^67 7M7z77777 8 8)8Y8o888888889$If $If^9989T:V:j::::::r;t;;;P}}}} $If^$Ifr$$Ifl$ 0s@$0(064 la;;;;;;<<sm$If & Fq$If^qh^h`r$$Ifl$ 0s@$0(064 la<<<(=)=*=+=,=-=J=^=} }wi[ & FA$If^A & Fq$If^q`$If  $If^ r$$Ifl0|$(064 laW ^=x=====%>&>h>U?V?a@@yoyo  $If^ r$$Iflp0$(064 laW$If & FA$If^A @#A+A0A7A8A9AbAiAtAAo]]] & F @A$If^A & F @q$If^qh^hr$$Iflp0$(064 laW$If AAAAAABBLBMBNB@CuPggggg @ $If^ r$$Ifl0z$(064 laW$If & F @A$If^A @CACUCmCCCCCgDhDDDGEHEIE4yyyyyyy @ $If^ r$$Ifl0z$(064 laW$IfIEJEKENEiEjEkE}k] @ $If^  & F @q$If^q @h^hr$$Ifl0z$(064 laW$IfkElEmEoEEEEucu]$If & F @q$If^q @ $If^ @h^hr$$Ifl0$(064 laWEEEEEEdEE $%YZciDNU\cdes =\} +N(@j 7`p      y z =Yu{|cdOP?WXlm r!0@LVW !"ey7BXy45./01[aqx9AFMNmn*A B Y j w v!w!"""""""##!#;#A#P#_#e#f###$/$Y$n$o$$$*%+%F%e%%%%%%%;&I&[&j&&&&&&&&&& '' '!'''4'A'K'}'''''''''''(((4(@(((()))E)F)S)a)s))))))))k*y*******+++=+a+y++++++6,Q,R,n,--A-g-}--------..).6.C.P.Q........./r/s////////0 0M0z00000 1 1)1Y1o11111111228222222233A3B3n3o3p3q3r3s3t33)4*4y4444444445525M5d5555667l888888888899o9p9q9r999999::::;;E;F;;;a<b<<<<<<<<<<<<<(=;=<===@=C=V=\===>>>>>>>>>9?:?;? 0> 0>000000000000 00 000000000000000000000000000000000000000 0  0gE 0gE000000000000."N,6C\  ul4!"B%'*+,-l/24569;<^=@A@CIEkEEFGILMMN-/012345789:;<=>?@ABDEFGHIJKLMNOPQRSTUVWXYZ[\N.RU)3FOZcv w~+2 47~X[:Q #\s58WZW\8A%%&&&&}''''''( ())++Z+^+|++++++++++++++g,m,,,,,6-?-----..*...7.;.D.H..../////"1(1)1211122F2I22222g3m333%4(4t4w4w5588Q9T9::;%;:;D;<<7=:=R>U>EchEMOTW[^bmr=I "=@\_} ?@bj  -6Y^',YZhi      z | GIdfk~?C  '(26FJLO!&h{ eh}~/E}')),8;CFOR\g}&)[`ajqwx-A !""""""""""%#)#I#J#X#Y#####$$/$1$Y$[$o$s$ %%+%4%F%O%e%n%%%%%;&?&I&M&[&_&j&n&&&&&&&&&&&&&&&''''''!'&')'*'6'7'C'D'L'O'}'''''''''''(((4(?(((c)h)u)z)))))++?+E+c+e+|++++++++7,;,R,V,- -B-I-h-p-~--------. ...*...7.;.D.H.Q.T.............*/8/u/x/////////00!0+0N0X0{0000 11]1a1s1v1111111<2?2222222C3L344445 55&525:5M5[55688888999:::;;;0;2;7;9;y;;<<x<<3=6=V=[===>>>>V?]?????@@3A7ArAxAAARBXBBBCCCCDDDDDDVE]ErEzE{EEE::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::ZiEegs=EFWZah  Ym @W9M @ B ` q =!v!!""#;#e#Y$m$%*%%%;&&&&& ''' ((^(c(a))))m**++y++++6,Q,R,n,--6.P.y.....///00 1)1Y11334d58899"99A<b<<<M=^=>>AAAcAyAABBBB\CnCoCCbDDEEEElizabeth S. Adams Administrator,C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\mso1D.doc xA\ ݒ|XT|XA%h*t 6Nxz9lETRmMHSn-5U_h GG^G`hH.h ^`hH.h  L ^ `LhH.h   ^ `hH.h ^`hH.h WLW^W`LhH.h ''^'`hH.h ^`hH.h L^`LhH.h hh^h`hH.h 88^8`hH.h L^`LhH.h   ^ `hH.h   ^ `hH.h xLx^x`LhH.h HH^H`hH.h ^`hH.h L^`LhH.h hh^h`hH.h 88^8`hH.h L^`LhH.h   ^ `hH.h   ^ `hH.h xLx^x`LhH.h HH^H`hH.h ^`hH.h L^`LhH.h ^`hH. ^`hH.$ $ ^$ `6o(hH.h@ @ ^@ `OJQJo(hH ^`hH. L^`LhH. ^`hH. ^`hH. PLP^P`LhH.^`o(. ^`hH. pLp^p`LhH. @ @ ^@ `hH. ^`hH. L^`LhH. ^`hH. ^`hH. PLP^P`LhH.^`o(. ^`hH. L^`LhH. Y Y ^Y `hH. ) ) ^) `hH. L^`LhH. ^`hH. ^`hH. iLi^i`LhH. B?B^B`?o( ^`hH. L^`LhH. Y Y ^Y `hH. ) ) ^) `hH. L^`LhH. ^`hH. ^`hH. iLi^i`LhH.^`o(. ^`hH. L^`LhH. Y Y ^Y `hH. ) ) ^) `hH. L^`LhH. ^`hH. ^`hH. iLi^i`LhH.^`o(. ^`hH. pLp^p`LhH. @ @ ^@ `hH. ^`hH. L^`LhH. ^`hH. ^`hH. PLP^P`LhH.  ^`o(hH. ^`hH. pLp^p`LhH. @ @ ^@ `hH. ^`hH. L^`LhH. ^`hH. ^`hH. PLP^P`LhH. 6A%T_xA\ -5UEmMHz9                     n               3R8                @Ȓ                l        Zides    WX rVW"45./01Nmn*""$%%''''@(((()))++n,--///)122n3o3p3t33)4*4y4444444d55556678889q9r99E;F;<<<<<<<<;=<===C=\=>>>>;??@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]_`abcdefghijklmnopqrstuvwxyz{|}~Root Entry Fp1Table^JrWordDocument"SummaryInformation(DocumentSummaryInformation8CompObjjObjectPoolpp  FMicrosoft Word Document MSWordDocWord.Document.89q