Menu

(Solved) : Informal Description Simple Language Statements Language Follows Read Read Integer Standar Q31043674 . . .

Here is an informal description of a simple language. Statements in the language are as follows:read a; | read an integer from standard input device into the variable a. a can be any lower case letter.wite a; | Write the value of a on standard output device (whatever it is). a can be any lower case letter.a := b; | Assign to the variable a the value of the variable b. a and b can be any letter between a and z.a := 58; | Assign the value of 58 to the variable a. a can be any letter between a and z. 58 can be any single digit or multiple digit integer. a := a + 1; | Add 1 to a. a can be any lower case letter.a := a – 1; | Subtract 1 from a. a can be any lower case letter.if a < 0 goto L;| If a < 0, transfer control to statement labeled with L. L can be any letter between A and Z. a can be any lower case letter.if a = 0 goto L;| If a = 0, transfer control to statement labeled with L. L can be any letter between A and Z. a can be any lower case letter.if a > 0 goto L;| If a > 0, transfer control to statement labeled with L. L can be any letter between A and Z. a can be any lower case letter.goto L; | Transfer control to statement labeled with L. L can be any letter between A and Z.halt; | Stop execution, program should always end with haltLower case letters a-z represent names of integer variables, upper case letters A-Z represent names of labels. Each statement may have a label as a prefix, separated from the statement by a colon (:). A program must have at least one statement and ends with halt. All statements end with ;.For example, the following program computes the sum of two positive integers a + b.Preconditions: Variables a and b contain positive integersPostconditions: Variable a contains the sum of the integers, the contents of variable b is destroyed.read a;read b;L: a := a+1; b := b-1; if b > 0 goto L;write a;halt;Task 1 (10 points): Using the statements of the simple language described above, write a program that computes the sum of two integers a and b, with the following specifications:Preconditions: Variables a and b contain any integers (might be positive, negative, or zero).Postconditions: Variable x contains the sum a + b, the contents of a and b are preserved.Note: You may use additional variables in your program if necessary. For simplicity, you may use single letter for variables and labels. Use lower case letter for variables and upper case letters for labels. Task 2 (30 points): Develop a formal definition of the language syntax using BNF notation. Make sure your grammar covers all the valid statements in this language.

Expert Answer


Answer to Informal Description Simple Language Statements Language Follows Read Read Integer Standar Q31043674 . . .

OR