Skip to content

Interpreter for Simple Expression Language (SEL)

License

Notifications You must be signed in to change notification settings

oshalabydev/sel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SEL

Simple Expression Language, SEL, is a tiny but powerful language.

Introduction

Simple Expression Language (or SEL) is a minimal and tiny language. It consists of expressions enclosed in parenthesis linearly arranged without nesting. The expressions are similar in syntax to LISP s-expressions. They may contain constants, function calls and pointers - they point (refer) to other expressions.

(sum 1 1)(mul $ 2)

The code above is equivalent to this expression:

$$2(1+1)$$

So it will return $4$. The dollar ($) character in the second expression is substituted by the interpreter with the value of the expression before it (i.e. the first expression, which has a value of $(1 + 1 =) 2$).

SEL is entirely built around this idea, i.e. the use of pointers for expressions to depend on each other. SEL has no nesting, however, pointers simulate nesting; you can rewrite the code above to:

(mul (sum 1 1) 2)

Here, we substituted $ with the first expression (sum 1 1). This will give you a better idea of how pointers work, however, it is invalid in SEL since nesting is not allowed.

Install

Currently, the package is not published; you cannot use pip to install it. However, you can clone the repository:

$ git clone https://github.com/oshalabydev/sel.git

and use the package with:

import sel

How To Use

SEL is entirely written in Python, and so it has a Python API (the details of the API are listed in the wiki).

To run some SEL code, make sure you have installed the package.

import sel

sel.eval("(print 'Hello World')")

Prints 'Hello World'

The example above uses the built-in function print, however, print doesn't return anything - it has a side effect instead.

The SEL interpreter (i.e. sel.eval) always returns the value of the last expression. Since print doesn't return anything, sel.eval returns $0$.

Another example (without print):

out = sel.eval("(12)(sum $ 2)")
print(out) # -> 14

More information on the SEL language and the SEL Python API can be found in the wiki.

Examples

Examples are serve as a nice introduction to the SEL language. By takin a look at them, you get an idea of the capabilities of SEL, and how it could be used.

Examples are located in examples folder, you can try them out. For example, you can try the getarea example (which gets the area of a circle provided a radius) with:

$ python -m sel.examples.getarea

You can contribute and add more examples if you want.


Contribution is highly appreciated

About

Interpreter for Simple Expression Language (SEL)

Topics

Resources

License

Stars

Watchers

Forks

Languages