About Posl

Posl is my personal project to create a prefix based language. It's been a hobby of mine for the last couple of years, working on it for a few hours each week.

It's an interpreted language that has the following flow:

  • reads a line of input
  • converts the input into tokens (Lexer)
  • converts the tokens into objects (Parser)
  • looks at the first object in the line and determines if there is a corresponding key in the current context and extracts the corresponding object (Interpreter)
  • if that object is an IExecutable, it passes the rest of the line into that object for execution and returns the result
  • If it's not an IExecutable, return the object without any processing.

An example of this is this piece of code that defines a function to provide an absolute value of a number

function abs (n) {
  if [< n 0] (* -1 n ) n
}

From the interpreter point of view this is all a single line. The parser converts the curly braces into a single object (MultiLineStatement) The if statement takes three objects, from the first object it expects a boolean and then it process either the first or second object based on the value of the boolean(all standard stuff).

The function could also be expanded to provide a bit of clarity:

function abs (n) {
    if [< n 0] {
        * -1 n
    } {
        n
    }
}

One of the neat things about this is that the MultiLineStatement can be passed around and re-used.


set val {
    if [< n 0] {
        * -1 n
    } {
        n
    }
}

function abs (n) val

Additionally, I've been working on making all of the core language constructs for the language optional. When the interpreter is initialized you can load library objects that define the  commands. 

Which gets to the point of all this, that you can define a domain specific language with the features of your choice. You want a command line terminal that provides a fixed set of commands. No problem. You want to allow the ability to define functions? done. Top level functions? not a problem.

In fact I've been able to put in quite a number of features that are considered high-end. All in a relatively small package.

In my unreleased code. I've actually split the core engine from the language into two separate packages. The core engine coming in close to 14k in size and the language another 20-30k

Things I'm eventually going to do:
  • Create a Logo language pack
  • Create a Basic language pack
  • Integrate a development environment
  • Provide access to run scripts from the command line, or through a socket connection
  • Improve the error handling