Give a CFGcontext free language that will work for the proce

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;

Solution

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

 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
 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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site