K31 Compilers | ||||||||||||||||||
Spring Semester 2022 | ||||||||||||||||||
|
Course ProjectDesign and implementation of a compiler for the MiniJava language (a small subset of Java) To implement the compiler you will use the tools JavaCC and JTB The implementation for phases 2 and 3 of the project will be done in Java utilizing the visitor pattern
Homework 1 - LL(1) Calculator Parser - Translator to JavaPart 1For the first part of this homework you should implement a simple calculator. The calculator should accept expressions with the bitwise AND(&) and XOR(^) operators, as well as parentheses. The grammar (for single-digit numbers) is summarized in: exp -> num | exp op exp | (exp) op -> ^ | & num -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 You need to change this grammar to support priority between the two operators, to remove the left recursion for LL parsing, etc. This part of the homework is divided in two parts:
Part 2In the second part of this homework you will implement a parser and translator for a language supporting string operations. The language supports concatenation (+) and "reverse" operators over strings, function definitions and calls, conditionals (if-else i.e, every &>
All values in the language are strings. The precedence of the operator expressions is defined as: precedence(if) < precedence(concat) < precedence(reverse). Your parser, based on a context-free grammar, will translate the input language into Java. You will use JavaCUP for the generation of the parser combined either with a hand-written lexer or a generated-one (e.g., using JFlex, which is encouraged). You will infer the desired syntax of the input and output languages from the examples below. The output language is a subset of Java so it can be compiled using javac and executed using Java or online Java compilers like this, if you > There is no need to perform type checking for the argument types or a check for the number of function arguments. You can assume that the program input will always be semantically correct. As with the first part of this assignment, you should accept input programs from stdin and print output Java programs to stdout. For your own convenience you can name the public class "Main", expecting the files that will be created by redirecting stdout output to be > To execute the program successfully, the "Main" class of your Java program must have a method with the following signature: public static void main(String[] args), which will be the main method of your program, containing all the translated statements of the input pro> |