YASL Interpreter

YASL Interpreter

Your task for this project will be to write an interpreter for YASL. Since we will want to use the console input/output for the interpreted program to interact with the user, the interpreter will need to take the name of the YASL source file as a command-line parameter.

For example, suppose that we have the demo program from the previous project (with one slight difference–can you spot it?) stored in the file demo3.yasl:

// This program shows just about all of YASL
program demo3;
{ Declare some constants }
const x = 6;
const y = 7;
const z = -120;
{ Declare some variables }
var a: int;
var b: bool;
var c1: int; var c2: int;
{ Declare some procedures }
proc foo;
const a = 42; // local to foo
var b: bool;
begin
c1 = x * y;
b = a == c1;
if b then
print “Hooray!”;
end;
proc bar(n: int, b: bool, var r: int);
proc fact(n: int, var r: int);
begin
if b or not b then
if n > 0 then
begin
fact(n – 1, r);
r = r * n;
end;
else
r = (y + x) mod 2;
end;
begin
while b do
begin
b = not b;
foo;
end;
fact(n, r);
end;
begin
prompt “Enter a number”, a;
bar(a, x < y, c2);
print “The answer is “””, c2–z+c1, “””!”;
prompt “Hit ENTER to end”;
end.

Running the program with argument “demo3.yasl” (in Java, this might look like java csc426.Project4 demo3.yasl, assuming your main class is csc426.Project4) should allow an interaction such as the following (user responses are in blue):

Enter a number 5
Hooray!
The answer is “42”!
Hit ENTER to end

More details about how to interpret YASL programs will come later.