CS335A-Compilers / CS335A-Compilers

Implementing a compilation toolchain, where the input is in Java language and the output is x86_64 Architecture based Assembly code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


Compiler for Java

Implementing Compiler for Java language.

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started

About The Project

We have implemented the lexical analayzer and parser for the Java language. The lexer returns various tokens and their lexemes to the bison parser where it matches the set of terminals with the java grammar. Finally, an Abstract Syntax Tree is created which shows different production rules which are applied to parse the java language.

Built With

Getting Started

You can clone the repository using the github clone option or download the zip file directly. Then follow the following instruction to run the analyzer.

Prerequisites

Your system must have latest version of flex, bison and graphviz installed. In order to install it in Debian system, enter the following command in your terminal

sudo apt-get install flex 
sudo apt-get install bison
sudo apt-get install graphviz

If you have any installation issues, you can refer to the flex installation guide or bison manual.

Evaluating Test cases

To evaluate different test cases present in tests folder you simply need to follow the below instructions.

Firstly, you have to change the current working directory.

cd src

Then compile the lexer and parser using makefile command.

make 

In order to evaluate the code on some java file (with path "../tests/test_1.java") and output the ast in assembly file (with path "./test_1.s"), use the following command.

./java-assembler --input=../tests/test_1.java --output=./test_1.s

This will generate .csv files containing the symbol table for each method and the whole class as a whole. It will also generate a dump of the 3AC instructions in the file - 3ac.txt

In order to vizualize the dot file in svg format, run the following command.

dot -Tsvg test_1.3ac -o test_1.svg

If you want to use help flag, you can simply use the following command.

./java-assembler --help

If one wants to see how the stack contents are changing and which particular production rule is being used, one can use the following command. (Remeber that verbose command will work only when you give some input and output file to it.)

./java-assembler --input=../tests/test_1.java --output=test_1.dot --verbose

Note

If the makefile does not compile properly, use the following commands,

  g++ lex.yy.c parser.tab.c ast.cpp helper.cpp symtab.cpp expression.cpp 3ac.cpp -o java-assembler

instead of

  g++ lex.yy.c parser.tab.c ast.cpp helper.cpp symtab.cpp expression.cpp 3ac.cpp -o java-assembler

in the Makefile

About

Implementing a compilation toolchain, where the input is in Java language and the output is x86_64 Architecture based Assembly code.


Languages

Language:Yacc 51.3%Language:C++ 39.3%Language:Lex 7.4%Language:Java 1.7%Language:Makefile 0.3%