Chapter 21: Problem 29
(Modifications to the Simple Compiler) Perform the following modifications to the Simple compiler. Some of these modifications may also require modifications to the Simpletron Simulator program written in Exercise 8.19 a. Allow the modulus operator (s) to be used in let statements. Simpletron Machine Language must be modified to include a modulus instruction. b. Allow exponentiation in a let statement using \(\wedge\) as the exponentiation operator. Simpletron Machine Language must be modified to include an exponentiation instruction. c. Allow the compiler to recognize uppercase and lowercase letters in Simple statements (e.g., 'A' is equivalent to 'a'). No modifications to the Simulator are required. d. Allow input statements to read values for multiple variables such as input \(x, y .\) No modifications to the Simpletron Simulator are required. [Page \(1055]\) e. Allow the compiler to output multiple values in a single print statement such as print a, \(b, c .\) No modifications to the Simpletron Simulator are required. f. Add syntax-checking capabilities to the compiler so error messages are output when syntax errors are encountered in a Simple program. No modifications to the Simpletron Simulator are required. g. Allow arrays of integers. No modifications to the Simpletron Simulator are required. h. Allow subroutines specified by the Simple commands gosub and return. Command gosub passes program control to a subroutine, and command return passes control back to the statement after the gosub. This is similar to a function call in \(\mathrm{C}++.\) The same subroutine can be called from many gosub commands distributed throughout a program. No modifications to the Simpletron Simulator are required. i. Allow repetition statements of the form for \(x=2\) to \(1 \theta\) step 2 simple statements next This for statement loops from 2 to 18 with an increment of \(2 .\) The next line marks the end of the body of the for. No modifications to the Simpletron Simulator are required. j. Allow repetition statements of the form for \(x=2\) to 10 simple statements next This for statement loops from 2 to 10 with a default increment of \(1 .\) No modifications to the Simpletron Simulator are required. k. Allow the compiler to process string input and output. This requires the Simpletron Simulator to be modified to process and store string values. [Hint: Each Simpletron word can be divided into two groups, each holding a two-digit integer. Each two-digit integer represents the ASCII decimal equivalent of a character. Add a machine-language instruction that will print a string beginning at a certain Simpletron memory location. The first half of the word at that location is a count of the number of characters in the string (i.e., the length of the string). Each succeeding half word contains one ASCII character expressed as two decimal digits. The machine-language instruction checks the length and prints the string by translating each two-digit number into its equivalent character. I. Allow the compiler to process floating-point values in addition to integers. The Simpletron Simulator must also be modified to process floating- point values. (A simple Interpreter) An interpreter is a program that reads a high-level language program statement, determines the operation to be performed by the statement and executes the operation immediately. The high-level language program is not converted into machine language first. Interpreters execute slowly because each statement encountered in the program must first be deciphered. If statements are contained in a loop, the statements are deciphered each time they are encountered in the loop. Early versions of the BASIC programming language were implemented as interpreters.
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.