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}
Compute the weakest precondition for the following sequence of statements, given the stated post condition. Hint: Start by deciding what variable or variables should be mentioned in the precondition. Recall the rule for sequences: the precondition for a statement in a sequence is equal to the post-condition for the statement that precedes it. Note: Your answer will involve a relationship between a and b. {??} x = 4 * (3 * y – x); y = 2 * x –...
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
Solve the following questions. All questions are mandatory. Q1: What’s wrong in the following grammar? S → ABC A → aA|aa B → bB|B C → cC|cccc Q2: Describe the strings generated by the following grammar S → aSa S → bSb S → aa S → bb Q3: Consider the following grammar: S → ABC A → aA|a B → bB|b C → cC|c Change the above grammar such that it generates L1={anbmck; n>=3,m>=3,k>=4} Q4: Use the following grammar...