a = 2 * (b - 1) - 1 {a > 0}
b = (c + 10) / 3 {b > 6}
<S> → <A>
<A> → <A> + <A> | <id>
<id> → a | b | c
1) i)
a = 2 * (b - 1) - 1 {a > 0}
2 * (b - 1) - 1 > 0
2 * (b - 1) > 1
(b - 1) > 1/2
b > 1/2 + 1
b > 3 / 2
Above is the weakest pre-condition.
1) ii)
b = (c + 10) / 3 {b > 6}
(c + 10) / 3 > 6
(c + 10) > 18
c > 18 - 10
c > 8
Above is the weakest pre-condition.
2)
Above are two parse trees for deriving a string aaa. So, it is ambiguous.
Please up vote. Happy learning!
Compute the weakest precondition for each of the following assignment statements and postconditions: a = 2...
2. Consider the following grammar: <assign> à <id> = <expr> <id> à A | B | C <expr> à <id> + <expr> | <id> * <expr> | ( <expr> ) | <id> Show a parse tree and leftmost derivation for the following statements: (a) A = ( A + B ) * C (b) A = A * ( B + C ) 3. [10 Points] Show that the following grammar is...
how do you solve this? em sets: Compute the weakest precondition for the following sequence of assignment statements and their postconditions (3pts]: a = 3 * (2 * b + a); b = 2 * a - 1 {b > 5}
Compute the weakest precondition for the following statements A. if (x == y) x=x*3 else x=x+1 {x < 0} B. x = 3 * (y + x); y= 3*x ; {y > 6}
3. Find the weakest precondition for the following sequence of statements and its post-condition: a-2b + 1; b = a - 3; {b > 2)
(20 pts) To understand the value of recursion in a programming language: implement the binary search algorithm first as a recursive function and again using a conditional loop. Your program should create an array of characters holding the letters ‘A’ – ‘Z’ and find the index in the array where the letter ‘K’ is stored. You may use any programming language that supports recursion. (5pts) Define syntax and semantics and give an example. (5pts) Why is it important for a...
Consider the following grammar (G1) for simple assignment statements. (The symbols in double quotation marks are terminal symbols.) assign → id “ = ” expr id → “A” | “B” | “C” expr → expr “ + ” expr | expr “ ∗ ” expr | “(” expr “)” | id a) Give a (leftmost) derivation for string A = B ∗ A + C. b) Give the parse tree for string A = B ∗ A + C. c)...
3. Using the grammar below, show a parse tree and a leftmost derivation for the statement. A = ( A + (B)) * C assign <idxpr expr>? <expr> <term> term <term factor factor (<expr>) l <term I <factor l <id> 4. Prove that the following grammar is ambiguous (Give sentence that has two parse trees, and show the parse trees):
Problem 3. f10 points for each of the following context-free grammars, i)use set notation to define the language generated by the grammar, and ii) Show that it is ambiguous by drawing 2 different parse trees for a string. a) Grammar: S + SaSb Si S + Sja | SibT T + Tb Tac b) Grammar: S + 151 T T + 1X1 X X + 0X01
Question 3: Given the following grammar: assign → id := expr expr → expr + term \ term term -term *factor lfactor factor-(expr) id Using the above grammar, show a leftmost derivation (first five steps) for the following assignment statement: A ((A B)+ C) a. [3 marks] b. Using the above grammar, show a rightmost derivation (first five steps) for the following assignment statement: A:-A+B+C)+A [3 marks] Draw the abstract syntax tree for each of the above statements [4 marks]...