CISC 223 - Assignment 6 (Winter 2014) Due: beginning of class (3:30 PM), Wednesday March 5 1. (4 marks) Use left-factoring and/or eliminate left-recursion to transform each of the below four grammars into a form that is suitable for recursive-descent parsing. As usual capital letters denote variables and lower case letters are terminals. (a) S -> abSa | abcSc | abdc | bcc (b) S -> aaaSb | acS | ab | bb (c) S -> Sc | Sad | bd | € (d) S -> SB | € B -> Bb |a 2. (1 mark) Consider the following correctness statement where S is any terminating code. Give the least restrictive condition that the code S has to satisfy in order to make the correctness statement valid. 1 ASSERT (false) S ASSERT (false) 3. (5 marks) What should the pre-condition P be in each of the following ten correctness statements for the statement to be an instance of Hoare's axiom scheme? All variables are of type int. (a) P { x = 1; } x == 1 (b) P { x = 1; } x == 0 (c) P { x = x + y; } 0 < x + z (d) P { x = x*z + 5; } x*x > y + 100 (e) P { x = x*y*z + 1; } y*y > z + 100 1 Note: This obviously is not a very "useful" correctness statement. Here you are just expected to determine when it is valid, as defined in section 2.2.
(f) P { x = y + 1; } ForAll (z = 1; z < 250) x + z - 1 > t + 1 (g) P { x=y + 1; } Exists(y = 0; y < 10) x + y == 100 (h) P { x = z + 2; } ForAll(z = 1; z < x) y + z < 100 (i) P { y = y + z; } Exists(y = 0; y < 100) y*y + z == 10 (j) P { x = x + y } Exists(y = 0; y < 100) (x + y == 15 | | z*x + y < 100) Regulations on assignments · The assignments may be done in groups consisting of one, two, three or four students. If more than one students are collaborating on an assignment, they must submit a single joint solution. . Clearly print (or type) the name(s) and student number(s), and course number, at the top of the first page. Additionally each student collaborating on an assignment must sign the top of the first page. . If the submission consists of more than one page, the pages must be stapled together. . Note: You are asked to write your solutions using non-erasable pen (or to type the solutions). Solutions written in pencil or erasable ink will be marked, but they will not be considered for remarking after the assignments are returned.