Skip to main content

DuCompiler


 Introduction:

Rabin Ranabhat, Connor Levenhagen and I, for our Senior Capstone Project, worked on building a compiler from scratch. We had about three months to do it but we really had no clue of what we were doing for the first month and a half. Although we knew plenty of what there was to know about compilers in theory, we soon realized that building one from scratch was not going to be easy. We started with baby steps, and by the time the project was due, we were taking giant leaps (we had no other option). In the end, it turned out to be a reasonably fine compiler and an excellent experience. During these three months, I had the best and the worst experiences of my academic life. Therefore, this project is really special.

Since this project belongs to two other people also, I won't be posting any source code. This post will just have some example code for Du-Compiler.

Finally, for anyone looking for a reasonably challenging senior projects, I would strongly encourage building a compiler. I say this for couple of reasons. First of all, it changes the way we look at code. It gives a better understanding of what exactly happens when the compile button is hit. In another words, it makes you aware of what is going on internally. Secondly, it involves learning/relearning several Computer Science topics such as regular expressions, hash table, data-structures, tree traversals, assembly level programming etc. It also involves A LOT of coding. When it all pans out, you are going to love what you have in your skill set. 

 Examples:

//Hello World
duhawk helloworld{
  duPrint(%Hello World%);
}

//Simple Addition
duhawk simpleAdd{ 
  int a;
  a=5;
  int b;    
  b = a + 5;
  duPrint b;  
}
//Result: 10


//Simple Pattern
duhawk test{ 
  int i;
  i=1;
  int j;
  j=1;
  while (i<=10){
   j=1;
   while (j<=i){
    duPrint(%*%);
    j=j + 1;
   }
   duPrintln(%%);
   i= i + 1;
  }
} 

/*
Result
*
**
***
****
*****
******
*******
********
*********
**********
*/


duhawk test{ 
int c;  
int d;     
duPrint (%Multiplication table of: %);  
duInput a;
duPrint (%upto: %);
duInput b;     

 for (c=1;c<=b;c=c + 1){
         duPrint a;
         duPrint (% X %);
         duPrint c;
         duPrint (% = %);
         d = a*c;
         duPrintln d;    
        }
} 

/*
Input for a = 19
Input for b = 15
Result:
Multiplication table of: 19
upto: 15
19 X 1 = 19
19 X 2 = 38
19 X 3 = 57
19 X 4 = 76
19 X 5 = 95
19 X 6 = 114
19 X 7 = 133
19 X 8 = 152
19 X 9 = 171
19 X 10 = 190
19 X 11 = 209
19 X 12 = 228
19 X 13 = 247
19 X 14 = 266
19 X 15 = 285
*/

Popular posts from this blog

SalsaNight

Zorgania

The Zorganian Republic has some very strange customs. Couples only wish to have female children as only females can inherit the family's wealth, so if they have a male child they keep having more children until they have a girl. If they have a girl, they stop having children. What is the ratio of girls to boys in Zorgania?
The ratio of girls to boys in Zorgania is 1:1. This might be a little counter-intuitive at first. Here are some ways of tackling this problem. 1. Monte Carlo Simulation: Although, Monte Carlo simulation does not necessarily show why the result is 1:1, it is appropriate because of the very counter-intuitive nature of the problem. At the very least, it helps us see that the result is indeed 1:1. Therefore, this is a good start.
The following R code estimates the probability of a child being a boy in Zorgania. 
couples <-100000 boycount <-0for (i in1:couples){ # 0: boywhile (sample(c(0,1),1) ==0) { boycount=boycount+1 } } probability <- boycount/(co…

Simple Launcher

A simple minimal launcher application for Android devices that shows battery percentage using lzyzsd's CirclProgress library (ArchProgress used in this case) and BroadcastReciever for battery state, Android's clock widgets, a built-in flash light switch and an app list view that can be toggled. Currently, the toggle simply filters all the app that I am working on at present. Future implementation can allow users to select their favorite apps or populate second toggle based on the most used applications.