231 Fall 2009 - Program 2 Assignment (original assignment dated 9/18/09; updated 9/24/09) (this file can be found in /home/mark/public_html/231/f09.program2) Due date: Thursday, October 1, by midnight Grading standard: correctness - 100% of grade; Submission: handin.231.1 2 - please submit all necessary files and a "translate" shell script Tools needed: chosen programming language other than m4 or perl This can be a team effort programming assignment. Maximum team size is three people. Your assignment is to implement the second approach described for programming assignment 1 in a language other than m4 or perl. An m4 solution for the second approach to program 1 is: (printed with additional newlines for readabaility) define(sub_imm,`sub(patsubst(_imm_$1,`-',`neg')) ifdef(`_immalloc_$1',,`define(_immalloc_$1)divert(1) `word'(patsubst(_imm_$1,`-',`neg'),$1)divert(2)')') define(add_imm,`add(patsubst(_imm_$1,`-',`neg')) ifdef(`_immalloc_$1',,`define(_immalloc_$1)divert(1) `word'(patsubst(_imm_$1,`-',`neg'),$1)divert(2)')') divert(2) include(source.m) divert(0) undivert A perl solution, written as a filter suitable for piping input, is: #!/usr/local/bin/perl @revised_program = (); %word_allocated = (); $line = ; while( $line ne "" ){ if( ($line !~ "add_imm") && ($line !~ "sub_imm") ){ if( $line ne "\n" ){ push( @revised_program, $line ); } }else{ $line =~ /\((.*)\)/; $value = $1; $name = $1; $name =~ s/-/neg_/; if( ! exists $word_allocated[$name] ){ print( "word(_imm_$name,$value)\n" ); $word_allocated[$name] = 1; } $line =~ s/_imm//; $line =~ s/\(.*\)/(_imm_$name)/; push( @revised_program, $line ); } $line = ; } print( @revised_program ); Your assignment is to program a solution in a third language so that we as a class can compare the ease of solution of the first programming assignment across multiple programming languages. You may assume that there will be only one assembly language statement per line of input. You may work in teams depending on the language choice. The size of the team should be commensurate with the amount of code required for the solution in your chosen programming language. For example, if you choose Ruby or Python, you should work as an individual. For Java or C++, your team should be at most two. For C, your team can be of size three. If you have any questions about language choice or team size, please email me. You do not have to follow the exact logic of either of the proposed solutions given above. Design your program logic to fit best with (and exploit) your chosen programming language. Your program should be written as a filter, that is, it should read from stdio and write to stdout. Do not hard-code file names. Please hand in all necessary files along with a "translate" shell script. The script should be conditional (perhaps via invoking make) so that if the needed executable file is not present, then any needed compile and link steps are performed. The grader should only need to use command line "./translate ___ ___" on each test file with an input file name and an output file name. For example, for the perl script above, the translate shell script could be one line: perl imm.pl <$1 >$2 where the script is stored in the file named imm.pl. Do not send tarballs.