Transcript Slides

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
MicroC 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;
initStack(stack);
Array *x = initArray(x);
stack = pushStack(stack, x);
Array *y = initArray(y);
stack = pushStack(stack, y);
insertInt(x,1,1);
int z = x->array[1].i;
printf("%d \n",z);
Array *ptr = NULL;
while (stackEmpty(stack)==0){
stack = popStack(stack, &ptr);
if( ptr != y ){
freeArray(ptr);
}
}
freeStack(stack);
return y;
}
Architecture
01.mc
Scanner
C
Executable
GCC
Tokens
Parser
01.c
AST
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