joshjava - JoshJava to MARIE Complier Joshua Zachariah...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: JoshJava to MARIE Complier Joshua Zachariah (Grade 11) and Jeff Edmonds (CS Prof 1 ) Abstract We describe what we learned while writing a compiler from a restriction of Java to MARIE assembler code. 1 Introduction Apology: Let us start by apologizing. Neither of us have taken a course or read anything on compilers or on MARIE. In our usual way, we prefer to piece it together ourselves. But we hope, this will give something that will be easy to follow by other novices. Perhaps someone will find some of it useful for a course. A Parser: My favorite algorithm of all time is a look-ahead-one parser. A context free grammar uses rules like exp ⇒ term + term + . . . + term term ⇒ fact * fact * . . . * fact to describe how an object like an expression x + y × z consists of the sum of terms x and y × z , while the term y × x consists of the product of factors y and z . The parsing algorithm takes such an expression as input and builds a tree showing its structure. It gets a routine GetExp to parse an expression x + y × z by recursively asking GetTerm to parse its terms x and y × z . Then GetExp builds the parse tree of this expression from the parse trees of the terms given to it by GetTerm . I teach this in my third year and grad algorithms courses. When my son Josh needed to do a final project for grade 11 CS, I was excited to do something here. A Complier: A compiler translates something from one language into another, for example, a Java program into machine code. Typically it makes two passes through the Java program. The first builds a symbol table explaining about all of the variable names, their types, and their scoping. The second pass parses the Java program building a parse tree describing the nested structures within the Java program. As this parse tree is built, it translates each little Java structure into the corresponding machine code structure. Having avoided the compiler course both as an undergrad and a graduate student because of the amount of coding required (and I turned down a job at IBM compiler group), I was inspired now to write a compiler. Both for ease of programming and for aesthetic reasons, I wanted it to be a one pass memoryless parser, meaning that it simply reads through the Java program once, parses it using a grammar, while spewing out the corresponding machine code. JoshJava: We started by restricting Java to make our task easier and to allow it to be compiled using one pass. At first, we thought that each routine must have the same fixed variable set all of type integers. But later we were able to have arbitrary sets of variable names. The only restriction was now is that global variables need to start with a capital and local variables with a small letter....
View Full Document

This note was uploaded on 02/13/2012 for the course CSE 4111 taught by Professor Edmonds during the Winter '12 term at York University.

Page1 / 41

joshjava - JoshJava to MARIE Complier Joshua Zachariah...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online