Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Give a CFG(context free language) that will work for the procedures below and an

ID: 3925816 • Letter: G

Question

Give a CFG(context free language) that will work for the procedures below and any other procedures that has the same kind of instructions.
PROCEDURE multiply a, b; VAR a, b, z; BEGIN z := 0; WHILE b > 0 DO BEGIN z := a + z; b := b - 1; END RETURN z; END; PROCEDURE odd x; VAR x; BEGIN WHILE x > 1 DO x := x / 2; IF x = 1 THEN RETURN 1; ELSE RETURN 0; END; Give a CFG(context free language) that will work for the procedures below and any other procedures that has the same kind of instructions.
PROCEDURE multiply a, b; VAR a, b, z; BEGIN z := 0; WHILE b > 0 DO BEGIN z := a + z; b := b - 1; END RETURN z; END; PROCEDURE odd x; VAR x; BEGIN WHILE x > 1 DO x := x / 2; IF x = 1 THEN RETURN 1; ELSE RETURN 0; END;
PROCEDURE multiply a, b; VAR a, b, z; BEGIN z := 0; WHILE b > 0 DO BEGIN z := a + z; b := b - 1; END RETURN z; END; PROCEDURE odd x; VAR x; BEGIN WHILE x > 1 DO x := x / 2; IF x = 1 THEN RETURN 1; ELSE RETURN 0; END; PROCEDURE multiply a, b; VAR a, b, z; BEGIN z := 0; WHILE b > 0 DO BEGIN z := a + z; b := b - 1; END RETURN z; END; PROCEDURE odd x; VAR x; BEGIN WHILE x > 1 DO x := x / 2; IF x = 1 THEN RETURN 1; ELSE RETURN 0; END;

Explanation / Answer

Z->A*B | B //for multiplying A and B

B->E | a    //where a is a string

2) S->X/2 | 1   //to find odd number

X->0 | 1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote