CS 257 (Spring 2005) Project: BASIC Compiler *
You will write a program in a purely functional subset of Scheme which
translates Lobo BASIC programs into Scheme programs. Note: Although your
compiler must be purely functional (e.g., it may not contain any
set!'s or display's), the Scheme code your compiler generates need not
be purely functional (e.g., it may contain set!'s and display's). The
project is organized as a set of milestones which correspond to
increasing letter grades:
- Satisfactory (C): Implement translation of arithmetic expressions
(i.e., +, -, *, /) and LET, INPUT, PRINT, and END. Successfully
compile and run Foo.
- Solid (B): All of the above plus translation of IF, GOTO, and
relational expressions (i.e., =, >, <, >=, <=, <>). Successfully
compile and run Quadratic Formula I.
- Good (B+): All of the above plus GOSUB, RETURN, FOR, and
NEXT. Successfully compile and run Quadratic Formula II.
- Very Good (A-): All of the above plus built in functions (e.g.,
LOG, ABS, RND, SQRT) and PRINT!. Successfully compile and run
Guess and
Hamurabi.
- Excellent (A): All of the above plus one and two dimensional
arrays. Implement DIM, ON GOTO, and ON GOSUB. Successfully compile and
run Battleship and Amazing.
- Righteous Hacker (A+): All of the above plus READ, DATA, RESTORE,
and strings, including MID$. Successfully compile and run
Hangman.
Some Lobo BASIC programs:
Hints
- Satisfactory (C)
- Write a function for renumbering BASIC programs. This will simplify the
process of translating BASIC programs.
- Write a function for converting infix arithmetic expressions to prefix.
- Write functions for translating LET, INPUT, PRINT, and END
statements into Scheme.
- Write a function which returns a list of all of the variable
names in a BASIC program. Make sure there are no duplicates.
- Write a function which will generate the Scheme program.
- Here is the annotated output of my
compiler for Foo.
- Solid (B)
- Write functions for translating IF and GOTO
statements into Scheme.
- Write a function which will translate a relational expression from
infix to prefix.
- Write a function which, given a BASIC relational operator, will
lookup the name of the corresponding Scheme function.
- Good (B+)
- Write a function for translating FOR and NEXT statements to LET,
IF, and GOTO statements. Use this to preprocess your BASIC program so that
you won't have to compile FOR's and NEXT's.
- Write functions for translating GOSUB and RETURN
statements into Scheme.
- Here is the annotated output of my
compiler for Quadratic Formula II.
- Very Good (A-)
- Extend your function for translating arithmetic expressions from
infix to prefix so that it works for expressions containing arithmetic
functions like LOG, ABS, RND, and SQRT.
- Write a function which, given a BASIC arithmetic function, will
lookup the name of the corresponding Scheme function.
- Excellent (A)
- Write functions for translating DIM, ON GOTO, and ON GOSUB statements.
- Write a function which returns a list of all of the array names in
a BASIC program.
- Rewrite the function which translates arithmetic expressions so
that it translates references to values in one and two dimensional
arrays and expressions which compute array indices.
- Write a function for translating IF statements which aren't
IF-GOTO's into IF-GOTO's.
- Rewrite the function which translates LET so that it handles
references to arrays on the left hand side of the equals sign.
- Righteous Hacker (A+)
- You will either have to do compile-time type analysis or generate
code which does run-time type checking to correctly compile BASIC's
overloaded string operators, i.e., +, =, <, >, etc.
- Write functions for translating DATA and RESTORE statements.
What You Should Hand In
- Listings of all your code.
- Translations of BASIC programs.
- Representative graphic output (where applicable).
When You Should Hand It In
The above should be handed in to the TA before Wed. May 11 at 5:00 PM.
* This webpage is located at http://cs.unm.edu/~williams/cs257/projects05.html