The source language we are translating from is a very simple toy language, with the specs given here: IttyBitty.
The translation approach is done in steps:
A coordinating ruby script is provided to translate an IttyBitty file to C (it takes the name of the input file as a command line argument, and displays the resulting C code)
A batch test script is also provided, that runs all the routines above on a collection of test cases.
Sample IttyBitty program | Resulting C translation |
start = 10 end = 200 index = start check = 150 total = 0 while ( index < end ) { total = total + index if ( index == check ) { total = total - check } index = index + 5 } print " the final total is " print total | #include <stdio.h> int main() { int start, end, index, check, total; start = 10; end = 200; index = start; check = 150; total = 0; while (index < end) { total = total + index; if (index == check) { total = total - check; } index = index + 5; } printf("the final total is \n"); printf("%d\n", total); return 0; } |