The issue of the assignment is to write a translator which translates a very simple high-level statement- and expression based language to a language understood by a stack machine. The language to be translated is somewhat modified from what is presented in Aho-Sethi-Ullman's book on pages 73-78. The stack language is presented on pages 62-69. An updated description can be obtained either on the excercise on thursday 30.9-99 or in the manual pages of the stack-language executing program executor.
The work is done using Java. You are given some 230 lines of code which already can read and translate a part of the input language to the stack language. Your task is to expand the translator so that it cover the whole language given below:
stmts -> stmt ';' stmts | stmt o stmt -> identifier ':=' expr | 'if' expr 'then' stmt o | 'while' expr 'do' stmt | 'begin' stmts 'end' | 'print' expr o expr -> expr '+' term o | expr '-' term o | term o term -> term '*' factor o | term '/' factor o | term 'mod' factor | factor o factor -> '(' expr ')' o | identifier | number oAll quoted ('') text represent a verbatim terminal symbol. The 'identifier's and 'number's are additional terminal symbols. All productions designated with a dot (o) are already implemented in the given code.
The recommended procedure is:
Here is the given code as a compressed tar-file. Build it by issuing e.g. javac Translator.java and run by java Translator. The translator reads the input language from stdin, writes stack language to stdout, and puts possible error messages to stderr.
The work can be done in almost any system. The stack language interpreter is in Niksula's Indys in ~tik76149/bin/executor. In the computing center's HPs and Alphas you should first say use edu/compiler, and then you can start the executor. If you use your own machines, you can obtain the source code of executor here.
The given code is organized slightly differently from what is given in Aho-Sethi-Ullmanin. The files are:
Return all the above mentioned code files with your modifications in them, and please highlight your modifications somehow. No additional documentation is needed. Check that you have your name and study book number in the returned papers. You should return the assignment on 21.10-99 to pigeon hole 45 in the main building or to the excercise held that day.
This assignment is personal, not a team effort. The grading is on the following scale:
|Returned on time||At most a week late|
Permission of returning the assignment more than a week late needs permission beforehand by electronic mail to firstname.lastname@example.org. Problems during the work can be discussed also by mail. Discussion hours have to be agreed beforehand.
The effect of this assignment on the course grade is 10%.