For this assignment, you are to complete an interpreter for a simple programming language named SILLY (Simple, Interpreted, Limited Language for You). For now, the SILLY language only contains three types of statements: assignments, output statements, and if statements. The grammar rules for the SILLY language are as follows:
The SILLY language is case sensitive, so variables a and A are considered unique. Variables are not explicitly declared, and are assumed to have initial values of 0 if not otherwise assigned. An assignment statement assigns an integer value to a variable. An output statement displays a single value (string or integer) on a line by itself. An if statement is controlled by an expression, where any nonzero value is considered to be true. Within the program file, whitespace (any sequence of spaces, tabs, and returns) separates the individual tokens (language elements) in a program.
SAMPLE PROGRAM OUTPUT x = 4 output "the numbers are" output x p2 = x + 2 output p2 - x + 5 output "done" the numbers are 4 7 done x0 = y + 1 output "x0 and y are" output x0 output y if x0 output "yes" else output "no" end x4 = x0 + output "done" x0 and y are 1 0 yes SYNTAX ERROR: malformed expression
An incomplete version of the SILLY interpreter is provided for you via the following classes/files:
The current interpreter implementation is incomplete. You will need to modify code to add the following functionality.
Note that in making these additions, the main progam file (interp.cpp) need not be modified at all. Instead, you will primarily be making changes to the various Statement classes, with some minor modifications to Token and Tokenizer. As you add new features, be sure that syntax errors result in an informative message being displayed.
Once you have the interpreter working correctly on programs involving all three types of statements, add an additional statement type: the while loop. The grammar rule for the new while loop is as follows:
A while loop performs conditional repetitions: as long as the loop test evaluates to true (i.e., the expression is nonzero), the statements inside the loop will be executed in sequence.