Package: pslmagic
This python module adds ipython magic for the ParselTongue language that
is part of theonline programming languages
classrun at
Brown.You can install this module usingpipas follows pip install
pslmagicNotes for Windows UsersIf you intend to use this module on Windows, you will need the do the
followinginstall and havebashon your PATH. An acceptable version of bash
is included in the Git for Windows installer, make sure to selectUse Git and optional Unix tools for the Windows Command PromptUse relative addresses when registering the executable and specifying
the test file base (see below).UsingpslmagicThe first step when usingpslmagicis to start the ipython notebook,
preferably from the command line in the test folder.ipython notebookLoad the magicStart a new notebook and run the following command to loadpalmagic%reload_extpslmagicWARNING:Please register the address of the ParselTongue executable            using %psl_exe <address>Register the ParselTongue interpreter(s)You need to download the parseltongue interpreter from theBrown CS1730
pageThen, call thepsl_exeto register the address for the execuable
(Use a relative address for Windows)%psl_exe/Users/tiverson/Desktop/osx-dist/bin/assignment1-osxLine magic to evaluate short commandsYou can evaluate a single line of ParselTongue using thepslmagic.
A single % indicateslinemagic%psl+(40,2)42Errors are thrown as python exceptions%psl5;7File "<string>", line unknown
SyntaxError: Encountered error while parsing, near: "" [line=#f, column=#f, position=#f]Use cell magic to evaluate longer programsYou can type a whole cell of ParselTongue using the%%pslcell
magic. The double % are used to indicate cell magic, and the remainder
of the current cell will be considered ParselTongue.%%psl# deffun defines a recursive functiondeffunfib(n)# operators like + and == are prefixif<(n,1)then0elseif==(n,1)then1else+(fib(-(n,1)),fib(-(n,2)))# The in ends the function body in a deffun, which can be followed by# another deffun, a defvar, or a braced expressionin# defvar creates a new variable with an initial value, bound inside the# body of the defvardefvarx=0in{# For loops have an initialization, a test, an update, and a bodyfor(x=0;<(x,10);x++){# print takes any value and displays itprint(fib(x));print(" ");};# The result of the program is the value of the last expression# evaluated.  It is printed, so we avoid printing it by terminating the# program with a """";}0 1 1 2 3 5 8 13 21 34Create tests for the test suiteYou can create a test for your test suite using the%%psl_create_testmagic. The first argument (on the%%psl_create_test line) is the base file name. Three files will be
createdbase.psl - contains the code in the cellbase.psl.expected - creates the output when running the code vs. the
correct interpreter.base.psl.error - contains any errors generated when running vs. the
correct interpreter%%psl_create_testtest_case# deffun defines a recursive functiondeffunfib(n)# operators like + and == are prefixif<(n,1)then0elseif==(n,1)then1else+(fib(-(n,1)),fib(-(n,2)))# The in ends the function body in a deffun, which can be followed by# another deffun, a defvar, or a braced expressionin# defvar creates a new variable with an initial value, bound inside the# body of the defvardefvarx=0in{# For loops have an initialization, a test, an update, and a bodyfor(x=0;<(x,10);x++){# print takes any value and displays itprint(fib(x));print(" ");};# The result of the program is the value of the last expression# evaluated.  It is printed, so we avoid printing it by terminating the# program with a """";}To inspect the resulting files, run the following commands%%bashecho"*******PSL FILE*******"lesstest_case.pslecho"*******EXPECTED RESULTS FILE*******"lesstest_case.psl.expectedecho"*******ERROR FILE*******"lesstest_case.psl.error*****PSL FILE*****# deffun defines a recursive function
deffun fib(n)
  # operators like + and == are prefix
  if <(n, 1) then 0 else
  if ==(n, 1) then 1 else
  +(fib(-(n, 1)), fib(-(n, 2)))
# The in ends the function body in a deffun, which can be followed by
# another deffun, a defvar, or a braced expression
in
# defvar creates a new variable with an initial value, bound inside the
# body of the defvar
defvar x = 0 in {
  # For loops have an initialization, a test, an update, and a body
  for(x = 0; <(x,10); x++) {
    # print takes any value and displays it
    print(fib(x));
    print(" ");
  };
  # The result of the program is the value of the last expression
  # evaluated.  It is printed, so we avoid printing it by terminating the
  # program with a ""
  "";
}*******EXPECTED RESULTS FILE*******
0 1 1 2 3 5 8 13 21 34*****ERROR FILE*****Run the test suite versus the 25 incorrect interpretersYou can run your test suite versus the 25 incorrect interpreters using
the%psl_run_testsmagic. The first argument is the address of the
execuable (again using relative addresses on Windows)%psl_run_tests/Users/tiverson/Desktop/sample-test-suite/bindings1:
Bug not found!
bindings2:
Differences in:
/Users/tiverson/Desktop/sample-test-suite/test_case.psl

bindings3:
Differences in:
/Users/tiverson/Desktop/sample-test-suite/test_case.psl
/Users/tiverson/Desktop/sample-test-suite/functions/func5.psl

bindings4:
Bug not found!
functions1:
Differences in:
/Users/tiverson/Desktop/sample-test-suite/functions/func5.psl

functions2:
Bug not found!
functions3:
Differences in:
/Users/tiverson/Desktop/sample-test-suite/test_case.psl

if-then-else1:
Bug not found!
if-then-else2:
Bug not found!
if-then-else3:
Differences in:
/Users/tiverson/Desktop/sample-test-suite/if1.psl
/Users/tiverson/Desktop/sample-test-suite/test_case.psl

loops1:
Bug not found!
loops2:
Differences in:
/Users/tiverson/Desktop/sample-test-suite/test_case.psl

loops3:
Bug not found!
loops4:
Differences in:
/Users/tiverson/Desktop/sample-test-suite/test_case.psl

loops5:
Bug not found!
objects1:
Bug not found!
objects2:
Bug not found!
objects3:
Bug not found!
objects4:
Bug not found!
operators1:
Differences in:
/Users/tiverson/Desktop/sample-test-suite/test_case.psl

operators2:
Bug not found!
operators2:
Bug not found!
operators3:
Bug not found!
sequence1:
Differences in:
/Users/tiverson/Desktop/sample-test-suite/test_case.psl

sequence2:
Differences in:
/Users/tiverson/Desktop/sample-test-suite/test_case.psl

You found bugs in 10/25 interpreters.Run versus a single interpreter withpsl_run_singleYou can use the line magicpsl_run_singleto run a test suite
against just one interpreter. The two arguments for this magic are the
interpreter name (seepsl_run_testsoutput) and the directory%psl_run_single <interp-name> <director>%psl_run_singleif-then-else3/Users/tiverson/Desktop/sample-test-suite/if-then-else3:
 2 tests succeeded.
2 tests failed.
== Output of failed tests ==
=====================================================
=   Results for /Users/tiverson/Desktop/sample-test-suite/if1.psl   =
=====================================================
=== Expected stdout ===
passed
passed
passed
passed


=== Actual stdout ===
failed
passed
failed
failed


=== Expected stderr ===

=== Actual stderr ===

=====================================================
=   Results for /Users/tiverson/Desktop/sample-test-suite/test_case.psl   =
=====================================================
=== Expected stdout ===
0 1 1 2 3 5 8 13 21 34

=== Actual stdout ===


=== Expected stderr ===

=== Actual stderr ===


You found bugs in 1/1 interpreters.