COL 106 Assignment 2



In this assignment you will create an interpretter with the help of a stack. In particular, your program will interpret (run) another "program" written in L106. L106 is a simple language and has only simple operations. An L106 program has a single statement per line. A statement can be one of:
  1. Variable assignment
  2. Function definition
Assignments are of the form:
SET name = expression
Function definition are of the form:
DEF name = expression
The output of the program is simply the value of the last assigned variable. When an assignment statement is encounterd by the interpretter, it computes the value of the expression on the RHS, and remembers it as the value of the variable named on LHS. When a function definition is encountered, the interpretter remembers the expression on the right hand side (in the form of a string) as the expression of the function named on LHS.

An expression consists of literals, names, and parentheses.

The inbuilt operator performs a special type of APPEND. It takes two arguments enclosed in parentheses as in (A B), and is defined below.


The APPEND operator is demonstrated below:
  1. ("apple" "eggs") => appleggs
  2. ("apple" "orange") => appleorange
  3. ("apple" "bean") => beanapple
  4. ("" "apple") => apple
A few simple L106 programs are given below.
SET A = "apple"

SET A = "snapple"
SET A = ($A "apple") 

Program: (See prog.txt)
DEF A = (($1 ($2 $X)) $3)
SET X = "white"
SET B = ("final" $A("first" "second" "third"))


Implement a public class Assignment2, with a static main that takes the name of the progam file on the command line. It reads the contents of the file, interpretting and executing it. The final output of the program is then written to System.out.

You should use one stack for evaluating each expression. Push on left parenthesis and perform APPEND on right parenthesis. If a variable is encountered, its value should be substituted on to the stack. If a function is encounterd, a runtime stack should be implemented to push the current state on to this runtime stack along with the function parameters and start evaluation of the corresponding expression. Function parameter values are fetched from the stack to include in evaluation.

Submission instructions

Submission will be at moodle. Link will be provided in due course.

Please ensure that you follow the following set of instructions meticulously while submitting the assignment on Moodle. Also, please note that in case of deviation from this procedure will render your submission faulty, and your assignment might not be evaluated at all by the script. Please follow these steps:

  1. On eclipse, by default, all your source files (.java files) are saved into a directory called "src" inside your project. You have to compress this directory (to zip format) and rename the zip file in this format:
    Example: If your entry number is 2012CSZ8019, the zip file should be named It should expand to a directory called src, which contains all your .java files. Please make sure that you follow exactly this naming format.
  2. Next, convert the zip file to base64 format. On any linux system, you can do this easily by issuing the following command on the terminal :
       base64 >
    This will create a file with the same name with a b64 extension appended at the end.
  3. Upload this b64 file on moodle and submit it (in the "Submission" section). After Submission, there is an option of "Evaluate" in the "Edit" section. Click on "Evaluate". On the right side of the window, you will get information about the submission status. On clicking the "Evaluate" link, you should see a script running and producing an output of your codes' performance against the standard set of test cases that we supply internally for the assessment. A dialog box will show you the messages on how your codes performed against the benchmarks that we provided.
        Important notes