Final Project Presentation Civ Eli BogomShanon Michael Nguyen
Final Project Presentation Civ Eli Bogom-Shanon Michael Nguyen Prateek Sinha Yuchen Zeng
Introduction Civ’s purpose is to provide a simplified version of C ●The motivation was to enable a user to quickly grasp fundamental programming concepts ●Civ is mean to serve as an intermediate step between Micro. C and C ●
Keywords Types Control Operators (in order of precedence) int for () , [] float while − , ! char if * , / , % String else + , − void break < , > , <= , >= continue == , != return && , || =
Features Dynamic Arrays ●Native support of dynamically sized arrays ●Multidimensional capability ●Garbage Collection ●Automatically deallocates arrays ●Allows user not to worry about memory use ●
How to Compile and Run ● Make . /civ --gcc < [Path to your. mc file] ●. /civ –h shows help ●. /civ –h shows flag list ● ● . /program_name. exe
Example of dynamic arrays int[] main(){ int x[]; int y[]; int x[1] = 1; int z = x[1]; printf("%d n", z); return y; }
Generated C code #include <stdio. h> #include "array. h" Array *main(){ Stack *stack = NULL; init. Stack(stack); Array *x = init. Array(x); stack = push. Stack(stack, x); Array *y = init. Array(y); stack = push. Stack(stack, y); insert. Int(x, 1, 1); int z = x->array[1]. i; printf("%d n", z); Array *ptr = NULL; while (stack. Empty(stack)==0){ stack = pop. Stack(stack, &ptr); if( ptr != y ){ free. Array(ptr); } } free. Stack(stack); return y; }
Architecture 01. mc Scanner Tokens Parser AST tic an r m yze Se al an C Executable GCC 01. c Code Generation SAST
Semantic Checking • ID name validation • Type checking for variable assignment • Type checking for function calls • Argument type and number checking for function calls • Dimension checking for dynamic arrays • Index type checking for dynamic arrays • Operations checking • Return type checking • Return statement checking
Dynamic Arrays Typedef struct Array { int datatype; union Data { int i; char c; float f; struct Array *a; } Data; union Data *array; size_t used; size_t size; } Array;
Garbage Collection typedef struct Stack { Array *data; struct Stack *next; } Stack;
Contribution Eli - C implementation of dynamic arrays and garbage collection ● ● Michael – Grammar, version control, test suite ● Prateek – Documentation, test cases ● Yuchen – Semantic analysis and code generation
Lessons Learned Eli – Communicate constantly ● Michael – Test constantly ● Prateek – Start earlier ● Yuchen – Think carefully before writing code ●
Demo • Fibonacci • Bubble sort
- Slides: 14