In the tar file 2_15.tar, you will find a parser for the calculator language in Chapter 2 of the text.

The code units are:

The objective in this exercise is to modify the calculator language to add "goto" syntax.

Update 2019-09-24: A student pointed out after class yesterday that the test file "test4.calc" uses "location" rather than "destination" as the keyword, so I have changed this page to match "test4.calc".

First, you will need to modify the parser to recognize a new instruction "goto LOCATION" in addition to its current suite of "read", "write", and assignment, and you will need to modify the parser to also recognize the label.

To recognize a LOCATION, you can use the already existing "identifier" regular expression.

For the LOCATION syntax; let's use "destination" as a keyword rather than the traditional postpositional ":".

Thus using our new goto syntax would might look something like:

read A
read B

goto D

write B

location D

write A
    

You can run tests by using the Makefile-tests; for example, you might do something like:

% ./test.bash
Success : test.calc was expected to pass, and it did
Success : test2.calc was expected to fail, and it did
Success : test3.calc was expected to pass, and it did
Success : test4.calc was expected to fail, and it did

However, since test4.calc actually tests the new goto code, you will want to change it from a "fail" test to a "pass" test.

Please make sure that the output of this parser (the graphviz code) reflects your new syntax; your parser output for test4.calc should look like test4.pdf.

Please tar your directory up when you finish, and submit it on Canvas by 11:59pm on Sunday, September 29.