SearchWiki:

CC Course 2005

PmWiki

Recent Changes Printable View Page History Edit Page

Fully Optimized Decent and Experimental C FodeC


Authors

  • Rudolf Dittrich rdittrich at cosy . sbg . ac . at
  • Lutz Findeisen lfindeis at cosy . sbg . ac . at
  • Werner Gitschthaler wgitscht at cosy . sbg . ac . at

Introduction

The FodeC programming is a subset of the C programming language.\\
It features:

  • Basic operation to control the execution of the program
  • Non primitive data types (struct)
  • Pointer to non primitve data types
  • dynamic memory allocation
  • basic I/O

Project Status

  • scanner -> done
  • parser -> done
  • codegenereation -> in progress
  • self compilation -> not finsihed

Reasons:

  • Major rewrite at the end of deadline (all dynamic structures thrown out of the parser, basically the parser was written new)
  • Projectmanagement was again not good enough to bring the project to an approriate end


.

fodeC Syntax

Keywords

if, elsif, else, while, struct, sizeof, return, break, char, int, string, write, open
close, read, printf

Comment ::= "/*" {Charset} "*/" | //.
Identifier ::= [Letter]{Letter | Digit}.
Constant ::= Zahl | "'"Letter"'".
Number ::= ["+" | "-"] Digit {Digit}.
Letter ::= "A" ... "Z" | "a" .. "z".
Digit ::= "0" ... "9".
Charset ::= ASCII.

Expressions

Simpleexpression ::= ["+" | "-"] Term {"-" | "+" | "||" Term}.

Term ::= Factor {"*" | "/" | "%" | "&&" Factor }.

Factor ::= ["!" | "sizeof"] Expression | Constant | Identifier | "(" Expression ")" |

Identifier"("[Parameter]")" | Lvalue "."Identifier["["Expression"]"].

Expression ::= Simpleexpression ["==" | "!=" | "<" | "<=" | ">=" | ">" Simpleexpression]

Parameter ::= [Expression] {"," Expression}.

Lvalue ::= Identifier ["[" Expression "]"].

Statement ::= Block | Expression ";" |

"if (" Expression ")" Statement |
"if (" Expression ")" Statement { "elsif (" Expression ")" Statement }"else" Statement |
"while (" Expression ")" Statement |
"break ;" |
"return ;".

Block ::= "{"{Datadeclaration}{Statement}"}".

Deklaration ::= Datadeclaration | Functiondeclaration.

Datadeclaration ::= Simpledeclaration | Structdeclaration.

Simpledeclaration ::= Typename Identifier ["[" Number "]" [Init]

{","Identifier["["Number"]" [Init]} ";".

Structdeclaration ::= "struct" Identifier "{"{Datadeclaration}"};"

Functiondeclaration ::= "func" Typename Identifier "(" Namelist")"Block.

Typename ::= "char" | "int" | "georgean".

Init ::= "=" Constant | "{"Constant{"," Constant }"}".

Namelist ::= Typname Identifier {"," Typname Identifier}.

Ioops ::= "read" | "write" | "open" | "close" | "printf".

Program ::= {[Deklaration]}.

Virtual Machine

The VM is implemented in C and is a port of Wirth's VM

Instruction Format

opcode a b c
4 byte 4 byte 4 byte 4 byte

Files

Project presentation: compiler.pdf
Software design description (old compiler): compilerSDD.pdf
Compiler(old): compiler_old.tar.gz Compiler(new): compiler_new.tar.gz

The code below ONLY compiles with the new compiler

  
int x;
int y;
int k; 
int o;
int t;
int tmp1;
int tmp2;
struct field{
	int ll[10];
	int g[10];
};

struct token{
	int fg[10];
	int pg[10];
	int name;
	struct field f;
};

struct token tok;


func void main();
func void structs();
func void recursion(int para_x,int para_y);
func int returner();
func void cond();
func void local_vars();

func void recursion(int para_x,int para_y){
	tmp1 = para_x;
	tmp2 = para_y;
	if(tmp1 == 9) {
		printf("===========================");
		printf("recursion called\n");
	}
	printf("got params %i %i \n",tmp1,tmp2);
	if(tmp1 > 0){
		tmp1 = tmp1 - 1;
		tmp2 = tmp2 - 1;
		recursion(tmp1,tmp2);
	}
}

func void local_vars(){
	int x;
	printf("===========================");
	printf("local hiding !\n");
	x = 4;
	tmp1 = x;
	printf("local x is %i \n",tmp1);
	break 3;
}

func int returner(){
	printf("===========================");
	printf("returner called, returns 5!\n");
	tmp1 = 5;
	return  tmp1;
}

func void cond(){
	printf("===========================");
	printf("cond called x should be 27\n");
	x = 8;
	y = 4;
	if(x > 9 && x > 7 ) {
		if(x > 9 || x < 7) {
			x = 21;
		} elsif( x > 7 ){
			x = 22;
		} else {
			x = 23;
		}
	} elsif(x > 7 && x < 7) {
		if(x < 7 ) {
			x = 24;
		} elsif( x < 8 ) {
			x = 25;
		} else {
			x = 26;
		}
	} elsif(x < 9) {
		x = 27;
	} else {
		x = 28;
	}
	printf("and x is : %i\n",x);
	break break;
}

func void structs(){
	printf("===========================");
	printf("structs called\n");
	x = 0;
	k = 30;
	y = 100;
	while(x < 10){
		tok.f.ll[x] = x; 
		tok.f.g[x] = k; 
		tok.fg[x] = k;
		tok.pg[x] = y;
		y = y - 1;
		k = k - 1;
		x = x + 1;
	}
	x = 0;
	while(x < 10){
		y = tok.f.ll[x];
		k = tok.f.g[x];
		o = tok.fg[x];
		t = tok.pg[x];
		printf("out %i %i %i %i\n",y, k, o, t);
		x = x + 1;
	}
}

func void main(){
	x = 9;
	y = 9;
	recursion(x,y);
	x = 20;
	break break;
	x = returner();
	printf("returner returned %i\n",x);
	break 2;
	cond();
	x = 50;
	printf("global x is %i\n",x);
	local_vars();	
	structs();
	printf("thx for checking me out \n");
}
 

Edit Page - Page History - Printable View - Recent Changes - WikiHelp - SearchWiki
Page last modified on July 19, 2005, at 07:17 PM