joshjava - JoshJava to MARIE Complier Joshua...

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

View Full Document Right Arrow Icon
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. MARIE: Our friend Gara told us about a very simple assembly language that is used in class rooms.
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern