Write a preliminary version of a BASIC interpreter.
This version can only do some simple tasks.
However, we shall enhance it gradually in the following weeks.
The program we are going to develop today is capable of doing the
following tasks:
When the user start the program, it prints out a welcome message.
After that, it enters an infinite loop, which continues to read a
line from the user and take some actions accordingly.
If the user enters a line of BASIC program (e.g. "10 A=B+C"),
which consists of a line number (between 1 and 32767) and a BASIC
statement, the interpreter will keep it in the memory.
If the user enters a line of code which has the same line number as
a previous line, the new one will overwrite the old one which exists in
the memory.
If the user enters a command "LIST", the interpreter will list all
lines of the BASIC program which the user has entered. Note that the
code must be listed ascendingly by the line numbers.
When the user enters "QUIT" or "SYSTEM", the program terminates.
For any other command, this BASIC interpreter will simply reply
Sorry. I don't know how to handle the command
"xxx" yet.
This version of BASIC interpreter is case-insensitive, so you may
convert all the input text to uppercase letters. (Note that this
behavior is different from the bwBASIC installed on
STU.csie.ncnu.edu.tw.)
(optional) If the user only enters a line number without any
succeeding statement:
If the memory stores a line with this line number, that line
will be deleted.
If there is no line with this line number, the BASIC
interpreter replies:
"ERROR: Line number xxx not found"
According to what you have learned up to now, you should be able to
write a C++ program to handle the above tasks with the statements you
learned from Chapter 1 to Chapter 4. If you need some sample programs
for string comparison, you can see Example of string
comparison of character arrays and
String comparison using pointers to char.
Deadline: 12/2 (Wed) 13:00