DOC PREVIEW
Columbia COMS W4115 - The C Flat language

This preview shows page 1-2-3-4-28-29-30-31-57-58-59-60 out of 60 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 60 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 60 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 60 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 60 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 60 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 60 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 60 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 60 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 60 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 60 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 60 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 60 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 60 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Cb.pdfCb (C flat)Nicolas Viennot 12/19/08Daniel BenamyCOMS W4115 – Final reportC Flat / ltcIntroductionThe C Flat language is mostly a subset of the C language. Some of the core functionalities of C has been stripped: there is no preprocessor, no structs, no strings, not even pointers. It's goal is purely educational.Originally Nico and Dan were working on two separate languages. The two projects merged, taking some features from each, and this is the resulting language.The ltc and C Flat language proposals are included in appendix A.C Flat TutorialC Flat is easy to use for any programmer familiar with a C-like language. The main differences from C are that there is only one type: the integer, variables don't have to be declared before use (but there are no global variables), and there are exceptions."Hello World" (outputs 1):main() { out(1);}Recursive Fibonacci:fib(n) {if (n < 3) return 1;else return fib(n-1) + fib(n-2);}main() {out(fib(in()));}Iterative Fibonacci:fib(n) {if (n < 1)throw 1;a = 1; // last fib #b = 1; // current fib #for (i = 3; i <= n; i++) {temp = b;b += a;a = temp;}return b;}main() {out(fib(in()));}Language ManualThe LRM is included in appendix B.Project Plan ProcessesWhen we merged projects, we decided to start off by implementing as much of the ltc proposal as possible and adding features from the original c flat proposal at the end if we had time. The ltc proposal clearly laid out the subset of C which we would be implementing. Since we were basing the language off of an existing one, there wasn't very much planning that had to go into figuring out how the language would work as far as the users are concerned.Our process for progressing through the project was to pick a feature that wasn't implemented and think through how exactly it should work and how it needed to be implemented. We sometimes had to compile some test C programs and look at the assembly generated or look up instructions in the Intel x86 manuals to learn exactly how something would work. Then we'd implement the feature and some tests for it. Sometimes we wrote the corresponding part of the LRM at that point and sometimes we filled it in later. This normally wouldn't be a great idea, but this language is small enough that it worked just fine.We had an automated tester which would run a series of code snippets through the compiler, run them, and verify that the output (or lack thereof) was correct. The tester was an improved version of the tester Dan used last fall in PLT. Initially we were also running the test suite that professor Edwards supplied with microc, but we eventually migrated to only our tester. It was quicker and easier to write tests for this tester because they all go in one file. After we did any work on the compiler, we'd run a quick "make test" and be able to verify that everything still worked correctly. Programming Style GuideFor the compiler, we stuck with the style already used in microc. More or less:• Indentation: 2 spaces.• Indentation level is increased when declaring a non trivial function (that is a function with at least one argument)• When matching, each case should be on it's own line. It also increase the indentation level.• Function names are in lower case with words separated by underscores.• Structures: names and fields are lower case with works separated by underscores.• Types: names lowercase, possible values first letter uppercase.• Tester uses standard python style as outlined in PEP 8 - http://www.python.org/dev/peps/pep-0008/• Tests: lower case variables and functions, 2 space indentation.For example, this is a snippet from backend.ml:let rec eval_expr_to_eax fdecl = function Literal(l) -> sprintf "mov eax, %d\n" l | Assignop(v, o, e) -> let assign_binop binop = eval_expr_to_eax fdecl (Assignop(v, Assign, Binop(Id(v), binop, e))) in (match o with Assign -> eval_expr_to_eax fdecl e ^ sprintf "mov [ebp+%d], eax\n" (id_to_offset fdecl v) | Add_assign -> assign_binop Add | Sub_assign -> assign_binop Sub | Mult_assign -> assign_binop Mult | Div_assign -> assign_binop Div Project Timeline• October: Proposals, automated tester.• November: Merged projects, first assembly program generated (skeleton, functions, basic operators, I/O, if, for, and while), LRM started.• December:• Week 1: Nothing.• Week 2: Many operators, proper argument evaluation, break, continue, exceptions.• Week 3: Static semantic analysis, compiler completed, LRM completed. Roles and ResponsibilitiesWe worked together on most aspects of the project. Nico implemented a number of language features on his own and Dan got the automated tester going. Software Development EnvironmentWe are both running a linux OS with its standard tools.Kate, Vim, and Nano Source code editingOcaml Tool Suite Lexer, parser, static and semantic analysis, backend, top level compiler driverGcc Compiling standard library (which is C), assembling output of the C Flat compiler, linking object filesPython Automated testerOpenOffice ReportLyx LRMGNU Make Project buildingProject LogWe used git as a version control system. The project history is:Nicolas Viennot 2008-12-18 10:47:49 -0500 style fixNicolas Viennot 2008-12-18 10:45:37 -0500 style fixNicolas Viennot 2008-12-18 10:39:08 -0500 style fixNicolas Viennot 2008-12-18 10:01:23 -0500 lrm updatedNicolas Viennot 2008-12-18 08:37:28 -0500 removed dead codeNicolas Viennot 2008-12-18 08:34:34 -0500 not pushing esp for exceptionNicolas Viennot 2008-12-17 21:44:26 -0500 added test for shifting negative numberNicolas Viennot 2008-12-17 18:03:25 -0500 removed the goto keywordNicolas Viennot 2008-12-17 16:45:58 -0500 added if/else test (2)Nicolas Viennot 2008-12-17 16:44:52 -0500 added if/else testDaniel Benamy 2008-12-17 16:05:22 -0500 Merge branch 'work'Daniel Benamy 2008-12-17 16:05:00 -0500 Renamed microc to cflat.Nicolas Viennot 2008-12-17 16:01:14 -0500 Assign is not an assignopDaniel Benamy 2008-12-17 15:54:58 -0500 Added a couple of tests for exceptions.Nicolas Viennot 2008-12-17 15:48:23 -0500 precedence change for < >Daniel Benamy 2008-12-17 15:47:16 -0500 Print compiler errors to stderr.Nicolas Viennot 2008-12-17 15:35:01 -0500 unclosed comment raise exceptionNicolas Viennot 2008-12-16 19:51:18 -0500 cleanupNicolas


View Full Document

Columbia COMS W4115 - The C Flat 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 The C Flat 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 The C Flat 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 The C Flat 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?