DOC PREVIEW
Columbia COMS W4115 - Arithmetic Calculation Language

This preview shows page 1-2-3-20-21-40-41-42 out of 42 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 42 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Arithmetic Calculation LanguageNathan CorvinoMay 12, 20111 Introduction! 51.1 Data Types! 51.2 Operators! 51.3 Control Structures! 51.4 Functions! 51.5 print! 51.5 Example! 52 Tutorial! 72.1 An First Example! 72.2 Compiling and Running! 72.3 Another Example! 83 Language Reference Manual! 93.1 Introduction! 93.2 Lexical Conventions! 93.2.1 Comments! 93.2.2 Identifiers! 93.2.3 Keywords! 93.2.4 Constants! 93.3 Variable Declarations! 103.4 Function Definitions! 103.4.1 print! 113.5 Expressions! 113.5.1 Function Calls! 113.5.2 Variable Access! 113.5.3 Multiplicative Operators! 123.5.4 Additive Operators! 123.5.5 Relational Operators! 123.5.6 Equality Operators! 123.5.7 Assignment! 123.6 Statements! 123.6.1 if Statement! 133.6.2 while Statement! 133.6.3 return Statement! 134 Project Plan! 144.1 Planning, Specification, and Development, and Testing process.! 144.2 Coding Style! 144.3 Development Tools! 154.4 Project Log! 155 Architectural Design! 165.1 Components! 166 Test Plan! 176.1 Examples! 176.2 Automation! 226.3 Test Suite! 247 Lessons Learned! 30A Grammar! 31B Code Listing! 33B.1 scanner.ml! 33B.2 parser.mly! 34B.3 compile.ml! 36B.4 acl.ml! 42B.5 Makefile! 421 IntroductionThe Arithmetic Calculation Language (ACL) focuses on arithmetic operations, combined with common procedural control structures. Itʼs primary motivation is to explore assembly code generation; as such it is primarily focused on remaining simple to keep this task tractable. At the same time, it does strives to explore as many different code constructs as feasible. It includes variables, conditionals, loops, and function calls.The syntax is c-like. Statements are terminated with a semicolon, and a list of statements can be enclosed in brackets.1.1 Data TypesACL supports ints and arrays of ints.1.2 OperatorsAddition, subtraction, multiplication, and division of integers is supported. Comparison operators <, >, =, <=, >=, and != compare int values, and return 1 if the comparison is true, 0 if false.1.3 Control StructuresACL supports while loops and if-else structures.1.4 FunctionsFunction calls are be supported, and the number of parameters in the definition and call has to match. There is no limit on the number of parameters for a function. Functions return ints.The program entry point is the main method, which returns an int. Passing command line arguments to it is not be supported.1.5 printACL has a built-in print function, that prints an int with a newline to standard output.1.5 ExampleAn example program, that illustrates these constructs in action:abs(int number){if (number < 0) {return -1 * number;} else {return number;}}power(int base, int exponent){int total;total = 1;while (exponent > 0) {total = base * total; exponent = exponent - 1;}return total;}int main(){int x;int y;x = 4;y = -3print(power(x, abs(y));}This sample program returns 64 when compiled by gcc, as expected; it does the same when compiled by the ACL compiler.This example demonstrates comparisons, looping, branching, and function calls.2 TutorialThe Arithmetic Calculation Language (ACL) is a simple procedural language for manipulating integers. Its is syntax is c-like, although greatly simplified.Programs start execution in a main function, and output results using the built in print function, performing integer calculations with standard operators.2.1 An First Exampleint main(){int x;int y;x = 4;y = -3print(x + y);print(x * y);print(x - 1);print(x / 2);}The above program proceeds by assigning values to the two variables defined, x and y, and then performing simple math with them. It outputs:1-12322.2 Compiling and RunningACL generates assembly code for the GNU Linux assembler. Furthermore, it depends on the standard c libraries, so the linker must be told where to load them. To compile and run a program, test.acl, the following commands would be executed:./acl -c < test.acl > test.sas -o test.o test.sld -dynamic-linker /lib/ld-linux.so.2 -o test -lc test.o./testThe first command uses ACL to generate the assembly code; the -c flag indicates compile. ACL prints its output to standard output, which is piped to test.sNext, the assembler is run on test.s, production and object file, test.o. This is linked using the linker, specifying the location of the dynamic linker, and output the test executable. Finally, that is run.2.3 Another ExampleA more complicated example, which illustrates a lot of the features of ACL, calculates whether a number is prime:prime(int a) { int i; int multiplier; int result; i = a / 2; while(i > 2) { multiplier = a / i; result = i * multiplier; if (result == a) { return 0; } i = i - 1; } return 1;}main(){ print(prime(7)); print(prime(37)); print(prime(42)); print(prime(45));}ACL does not include remainder division, so a search for divisors proceeds by trying to divide, then multiply the division result, by all the integers between 3 and half of the argument to prime. If the result of dividing and re-multiplying produces the starting number, then a divisor is found, and 0 is returned. Otherwise, 1 is returned.A while loop is used to try each number, subtracting one each time through the loop.3 Language Reference Manual3.1 IntroductionThis reference manual describes the Arithmetic Calculation Language (ACL), a small subset of C that allows numeric calculations to be done in a procedural fashion. The language only allows integer values to be manipulated, hence the name Arithmetic Calculation Language. It does, however, allow for arrays of integers to be declared, and provides a language features that are illustrative of the core procedural constructs: variable declarations, function definitions, selection, and iteration.Ints in ACL are 32 bits; it generates 32-bit Linux assembly code, and the data values are handled by the machine. No checks are done for overflow or underflow; the behavior of programs which produce such results is undefined.3.2 Lexical ConventionsA program consists of a single file, containing global variable declarations and procedure definitions. Execution begins with the function named main, which is required.3.2.1 CommentsComments are introduced by /* or //. Comments introduced by /* are terminated with */, while comments introduced by // terminate at the next newline.3.2.2 IdentifiersIdentifiers consist of letters, digits, and underscores, and must begin with a letter or underscore; case is significant.3.2.3 KeywordsThe following identifiers are used as keywords, and may not be used as


View Full Document

Columbia COMS W4115 - Arithmetic Calculation Language

Documents in this Course
YOLT

YOLT

13 pages

Lattakia

Lattakia

15 pages

EasyQL

EasyQL

14 pages

Photogram

Photogram

163 pages

Espresso

Espresso

27 pages

NumLang

NumLang

6 pages

EMPATH

EMPATH

14 pages

La Mesa

La Mesa

9 pages

JTemplate

JTemplate

238 pages

MATVEC

MATVEC

4 pages

TONEDEF

TONEDEF

14 pages

SASSi

SASSi

16 pages

JTemplate

JTemplate

39 pages

BATS

BATS

10 pages

Synapse

Synapse

11 pages

c.def

c.def

116 pages

TweaXML

TweaXML

108 pages

Load more
Download Arithmetic Calculation Language
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Arithmetic Calculation Language and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Arithmetic Calculation Language 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?