williamho/compiler — pull request #5 by williamho (2012-12-30 03:36:28+00:00)
Title: Asgn6

Tested to work with the following program (as well as empty statements in `for` loops such as `for (;;)`)

```c
int x;

main() {
x = 50;
printf("global variable x is %d\n\n",x);
pointers();
printf("after leaving function, global variable x is still %d\n\n",x);
fibonacci();
continues_and_breaks();
printf("the function returnval() returned %d\n\n",x=returnval());
dec2bin();
}

pointers() {
int x, *p;
x = 0;
printf("in function, local var x is %d\n",x);

printf("changing values via pointer indirection\n");
p = &x;
*p = 1234;
printf("in function, local var x is now %d\n\n",x);
}

fibonacci() {
int arr[15], i;
arr[0] = arr[1] = 1;
printf("fibonacci using a while-loop:\n%d %d ",*arr,*(arr+1));
i = 2;
while(i<15) {
arr[i] = arr[i-1] + arr[i-2];
printf("%d ",arr[i++]);
}
printf("\n\n");
}

continues_and_breaks() {
int i;
printf("example of continues and breaks in for-loop:\n");
for (i=16; i>=0; i--) {
if (i>8 && i%2) {
printf(". ");
continue;
}
if (i<3)
break;
printf("%d ",i);
}
printf("\n\n");
}

returnval() {
int retval;
printf("this function returns the value %d\n",retval = 21475);
return retval;
}

dec2bin() {
int i, flag;
printf("left/right shift example\n");
printf("%d in binary is: ",x);
for (i=1<<16; i>0; i>>=1) {
printf("%d",(i&x)!=0);
}
printf("\n\n");
}
```

Output of the compiled program:
```
global variable x is 50

in function, local var x is 0
changing values via pointer indirection
in function, local var x is now 1234

after leaving function, global variable x is still 50

fibonacci using a while-loop:
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610

example of continues and breaks in for-loop:
16 . 14 . 12 . 10 . 8 7 6 5 4 3

this function returns the value 21475
the function returnval() returned 21475

left/right shift example
21475 in binary is: 00101001111100011
```