CC Course 2005PmWiki |
Fully Optimized Decent and Experimental C FodeCAuthors
IntroductionThe FodeC programming is a subset of the C programming language.\\
Project Status
Reasons:
. fodeC SyntaxKeywordsif, 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.
ExpressionsSimpleexpression ::= ["+" | "-"] Term {"-" | "+" | "||" Term}. Term ::= Factor {"*" | "/" | "%" | "&&" Factor }. Factor ::= ["!" | "sizeof"] Expression | Constant | Identifier | "(" Expression ")" |
Expression ::= Simpleexpression ["==" | "!=" | "<" | "<=" | ">=" | ">" Simpleexpression] Parameter ::= [Expression] {"," Expression}. Lvalue ::= Identifier ["[" Expression "]"]. Statement ::= Block | Expression ";" |
Block ::= "{"{Datadeclaration}{Statement}"}". Deklaration ::= Datadeclaration | Functiondeclaration. Datadeclaration ::= Simpledeclaration | Structdeclaration. Simpledeclaration ::= Typename 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 MachineThe VM is implemented in C and is a port of Wirth's VM Instruction Format
FilesProject presentation: compiler.pdf 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");
}
|