Question: Solve these problems any help would be much appreciated!
Part 1: The subsequent grammar, is ambiguous.
à if then | if then else |
à e1 | e2 | . . . | en
Show that the grammar is unambiguous; how does it attach the else statement? If this is not the attachment you wanted, how would you need to write the code?
Part 2: Given the subsequent code fragment, where x is a number.
{ y >= 0 }
z = 0
n = y
while (n > 0) begin
z = z + x
n = n - 1
end
What does it compute? Prove it, showing how you derive the loop invariant.
Can you show that the grammar is unambiguous?