SPL Facade

TL;DR

We demonstrate the SPL Object subclass: #SPL instanceVariableNames: '' classVariableNames: '' package: 'GToolkit-Demo-SPL-SPL' Facade class for the PetitParser SPL case study.

SPL Facade

SPL Object subclass: #SPL instanceVariableNames: '' classVariableNames: '' package: 'GToolkit-Demo-SPL-SPL' is a simple Facade class for the SPL parser and interpreter, containing a few examples and convenience methods.

To parse and interpret a program, and print the final output, use SPL>>#run: run: anSPLProgramSource "Reduce the program and return the output" ^ (self reduce: anSPLProgramSource) output .

SPL run: 'print "Hello world!";'
  

To obtain an interpreter (context) for a program, use SPL>>#contextFor: contextFor: anSPLProgramSource "Return a runnable SPLContext for the SPL program" ^ SPLContext for: anSPLProgramSource .

SPL contextFor: 'print "Hello world!";'
  

To obtain an interpreter for expressions rather than programs, use SPL>>#contextForExpression: contextForExpression: anSPLExpressionString "Return a runnable SPLContext for the SPL expression" ^ SPLContext forExpression: anSPLExpressionString .

SPL contextForExpression: '6*(3+4)'
  

To reduce a program to its final state, use SPL>>#reduce: reduce: anSPLProgramSource "Reduce the program and return the context in the reduced state" ^ (self contextFor: anSPLProgramSource) reduce; yourself .

SPL reduce: 'print "Hello world!";'
  

SPL demos

Here are a few simple demo programs you can try or modify. (You can edit the code before stepping or reducing.)

SPL empty. "The empty program"
  
SPL hello. 
  
SPL factorial. 
  
SPL fibonacci.
  
"The non-terminating program. Step, but don't reduce!"
SPL omega.