You will also need to modify the symbol table to store information such as the address in memory that a variable or constant is stored, the type of entry in the symbol table (e.g. constant, variable, temporary). Note that the address field may be "unknown".
You will also need to implement a link method which converts the symbolic RAL instructions to absolute RAL instructions (i.e. hard coded addresses). This may be done after the program is translated and all necessary information is in the symbol table (i.e. the number of constants and their values, and the number of parameters, program variables, temporary variables, and the number of instructions for each procedure that was defined with a Define Statement). Since there are possibly multiple procedures you will have to decide how to order the code for the different procedures. It is beneficial to treat the main program as a procedure that is called first when the program is executed. You will need to know the number of instructions, parameters, local variables, temporary variables when generating the code for function calls. Finally, you will need an indirect jump (JMI) instruction to jump to the return address (i.e. the instruction to execute after returning form a function call) which is stored in the activation record for the called procedure. If you want to you may introduce a call instruction (perhaps a psuedo instruction, i.e. one that gets mapped to a sequence of real instructions) that does the jump to the procedure call and possibly some other actions such as storing the return address in the activation record (you could compute this in terms of the PC).
Finally, a compile method simply calls the translate and link methods. After compiling you can dump the RAL program to a file (or standard out) and then you may execute it on the RAM simulator.
You must test your compiler on several mini language programs which define and use procedures.
Students should submit their solution electronically via Blackboard Vista. Only one submission is required per group. The group leader for the assignment should submit the assignment.
The README file should describe all files that are included, contain instructions how to build [you should use make or Ant to build you program and make sure it successfully builds and runs on the CS compute server tux] and use the code, and outline how the code works. The README file should also contain a list of all group members and the group leader for the submitted assignment. You should also indicate how you tested your code. If your program is not working, you should clearly state this in the README file. Code should be documented (clear specifications and comments for any tricky parts of the code).
Okay, memory size. I will set an environment var called RAM_MEM before running your run target . It is quite simple to read an environment variable in a makefile:
foo : echo $$RAM_MEM
You can test it like this:
$ RAM_MEM=300 make foo
, or, if you add it to your environment, remember to export it. Please don't set it in your makefile.
Since you can do this in a number of languages, submit a makefile or Ant file. Here is a sample makefile. Please ask for help w/makefiles.
Submit the following files to Bb Vista:
moreutility) all of your source code (excluding the modified RAM)
You can name the the files as you wish. Your interpreter will read stdin, as previously.
catto display your symbolic RAL program (produced in translate) to stdout.
catto display your compiled (not optimised) RAL program (produced in translate to stdout.
Submit a gzipped tar file, called A6.tar.gz (the tar file should contain a directory called A6 which contains the files). The tar file should contain source code, instructions how to run your programs, sample input and output files, and a README file.
Note: Please pay attention to file names. E.g.,
makefile is not
README is not