Arithmetic Calculation LanguageNathan CorvinoFebruary 8, 2011The Artihmetic Calculation Language (ACL) focuses on arithmetic opera-tions, combined with common procedural control structures. It’s primarymotivation is to explore assembly code generation; as such it is primarilyfocused on remaining simple to keep this task tractable. At the same time,it does strives to explore as many different code constructs as feasible. Itincludes variables, conditionals, loops, and function calls.The syntax is c-like. Statements are terminated with a semicolon, and a listof statements can be enclosed in brackets.Data TypesACL will support floats and ints, although it will not necessarily supportautomatic type coerecion.OperatorsAddition, subtraction, multiplication, and division will be supported, on ei-ther ints or floats. Cast operations will be supported for converting betweenfloats and ints.Comparison operators allowed will be <, >, =, <=, >=, and !=.1Control StructuresACL will support while loops and if-else structures.FunctionsFunction calls will be supported, and at least four parameters will be sup-ported. Return types of int, float, and void—that is, no return type—will besupported.The program entry point will be the main method which returns an int.Passing command line arguments to it will not be supported.ExampleAn example program, that illustrates these constructs in action:int abs(int number){if (number < 0) {return -1 * number;} else {return number;}}int power(int base, int exponent){int total = 1;while (exponent > 0) {total = base * total;exponent = exponent - 1;}return total;}int main(){float x = 4.;int y = -3;return power((int) x, abs(y));}2This sample program returns 64 when compiled by gcc, as expected; it shoulddo the same when compiled by the ACL compiler.This example demonstrates ints and floats being used in conjuction withcasts, comparisons, looping, branching, and function
View Full Document