Sunteți pe pagina 1din 2

We are the student of Computer Science Engineering, we have done our

summer internship in Indian Institute of Technology Bombay under


TEQIP. In the entire internship programme, we are mentored by Prof.
Uday Khedkar.
In our internship we develop a compiler for the little Quilt(a demo
language). The Entire internship is divided into six assignments. Each
assignment includes step by step procedure for developing a compiler. At
the end of internship, we learned a lot about compilers like How compilers
work, How to use tools such as Yacc and Lex.
We learned many new programming concepts such as Abstract Syntax tree
and its evaluation, This makes our data structure and algorithm far much
better. At IIT Bombay we all feel a positive and healthy environment for
studies.
We all grateful thanks TEQIP for organizing such a great internship
program. Further details of the internship are provided in the same report.
Little Quilt

Little Quilt is a very small language for designing quilts. It is based on ML


syntax.
Scanner and Parser

We learnt the flex and bison tools which generate program segments that
can read the source program and discover its structure. The translation
rules in our lex script recognizes all the symbols in our input and returns
the corresponding token(s). The lex script also de nes regular expression
for the whitespaces and takes no action when the whitespaces are found in
the input.
Constructing the Abstract Syntax Tree

To construct the AST for a given expression, we defined an abstract base


class for Expression (Exp Node). We also defined it's subclasses
corresponding to the ASTs of 'a' (A AST), 'b' (B AST), 'turn' (TURN AST)
and 'sew' (SEW AST). The abstract class contains a virtual function print(),
which implies that all of its subclasses must implement the print() function
to print their respective ASTs to the file or standard output.
Evaluating the AST

For the turn(arg) operation, where 'arg' is the expression passed to turn
function as an argument, We have to first compute the matrix for 'arg', and
then rotate it 90 degrees clockwise to obtain the resulting matrix. Note that
each element of the matrix for 'arg' will be rotated by 90 degrees in
addition to the 90 degrees clockwise orientation of the whole matrix.
For the sew(arg1, arg2) operation, where 'arg1' and 'arg2' are the
expressions passed to sew function as arguments. We have to compute the
matrices for 'arg1' and 'arg2' and then combine these matrices to obtain the
resulting matrix. Note that the number of rows in the matrix for 'arg1' and
the matrix for 'arg2' must be same.
The way we implemented the evaluation mechanism is by first creating a
virtual function called evaluate() in our base class for Expression, so that
each of its subclasses must implement this evaluate() function to compute
their corresponding matrix.

Compiling the AST & generating the C++ code

For generating the equivalent C++ code for a given AST, we first tried to
create a global variable which was a vector of strings to act as a stack of
function calls and to store the expressions which are assigned to temporary
variables (of type 'Quilt'). We declared a global variable to keep track of
the total number of temporary variables. And then we created a print
function to print the C++ code using the stack (a vector of strings) and the
temporary variable counter. We also use Quadruple in this.

Let bindings for defining VAL and FUN

This allows us to define our own variables and functions and use them in
our expressions. The main challenge was to find the scope of the variable
or the function in the expression. This is done by creating a stack of
symbol tables and pushing a symbol table for every LET expression and
popping off that symbol table from the stack after the end of let
expression.

S-ar putea să vă placă și