


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!



(a) The set of floating point numbers over the alphabet { 0-9,. }. For example, strings “0.52”, ”35.” and “100.63” are in the language, but “1.01.5”, “35” (an integer number with no floating point) are not. (b) The set of strings over {1,0} that contain no substring 101. For example, strings “0100” and “10010” are in the language, but string “0101” is not.
1 program main(input, output); 2 var x : integer; 3 function F1(a : integer ) : integer; 4 begin 5 x := a + 3; 6 F1 = x; 7 end; 8 procedure P;
9 var a: integer; 10 function F2(b : integer) : integer; 11 begin 12 F2 := a + F1(b) 13 end 20 begin 21 a := 5; 22 writeln(F2(a)); 23 end; 24 begin 25 P 26 End.
a = b * c * a + b - (c - 2); while (b < c || a < c) { b = b * b; a = a * a; }
Use short-circuit evaluation for translating boolean expressions. Assume we have an infinite number of registers and that all variables can be allocated to registers without a memory address. Therefore no memory load or store operations are necessary. You can use ra, rb, rc to denote the registers for variables a, b, and c respectively, and use r1,r2,... to denote registers allocated for temporary values. You can use the following operations in your translation, where r1,r2,r3 are registers, num is an integer number, and L1,L2 are labels.
PLUS r1, r2 => r MULT r1, r2 => r SUB r1, r2 => r SUBI r1, num => r COMP r1, r2 => r COMPI r1, num => r CBR_LT r1 => L1, L JUMPI L
a := b + c b := a - d L1:c := c + 1 if (c > d) goto L a := a + d d := d * c b := a - b
(a) List three program optimizations that you’ve studied in class. Briefly summarize the optimization in 2-5 sentences. Specifically, what are they used for? What program analysis (i.e., what information regarding the input program) do they require?
(b) List three components that belong to the backend of most modern compilers. Summarize each component in 2-5 sentences. Specifically, what is the function- ality of each component? Specify a popular algorithm used in each component. (c) What are the definition(meaning) of LL(1) and LR(1) parsers? Summarize the parsing steps in 3-6 sentences for each kind of parsers. What are the respective rows, columns, and entries of a LL(1) or LR(1) parse table?