- Java in-built stack may be used. (So can lists, character and string functions.)
- For this assignment, Makefile is now optional, but encouraged. README must be provided.
- L106 specs only refer to letters (not characters). Hence it is NOT case sensitive.
- More examples:
SET Y = "why"
DEF A = (($1 ($2 $Y)) $3)
DEF B = ($1 $A($2 $X "good"))
SET Y = "because"
SET X = "white"
SET B = ("disturb" $B("first" "second"))
DEF FOO = ($1 $2)
SET X = "blood"
SET X = ("join" $FOO("first" $FOO("third" $X)))
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:
- Variable assignment
- Function definition
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.
Assignments are of the form:
- SET name = expression
- Function definition are of the form:
- DEF name = expression
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
and is defined below.
Literal is a double quote delimited word. A word is a sequence of letters of the English alphabet. Thus
is an example literal.
Name is a $ sign followed by either a word or a number (>0).
are example names. If $ is followed by a word, it refers to a variable or a function whose value is substituted to evaluate the expression. (If the variable as not encountered earlier during the execution, the value is assumed to be null. An undefined function always returns null. All names are global.)
A $ followed by a number refers to a positional function argument passed by the caller. For example, $1 refers to the first argument, $2 the second, and so on. A positional argument not sent by the caller implies null.
Parentheses are used to delimit the arguments of functions (and providing order of precendence). They also denote an in-built APPEND operator as described below.
If the last letter of the first string is the same as the first letter of the second string, the result is a concatenation, but without one of the copies of that common letter.
If the last letter of the first string occurs earlier in the alphabet than the first letter of the second string, the result is a simple concatenation.
If the last letter of the first string occurs later in the alphabet than the first letter of the second string, the result is a concatenation with the second string appearing before the first.
- If either of the strings is null, the output is the other string.
The APPEND operator is demonstrated below:
A few simple L106 programs are given below.
("apple" "eggs") => appleggs
("apple" "orange") => appleorange
("apple" "bean") => beanapple
("" "apple") => apple
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 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:
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 2012CSZ8019_assignment2.zip. It should expand to a directory called src, which contains all your .java files.
Please make sure that you follow exactly this naming format.
- 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 entrynumber_assignment2.zip > entrynumber_assignment2.zip.b64
This will create a file with the same name with a b64 extension appended at the end.
- 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.