Code Monkey home page Code Monkey logo

sel's Introduction

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 calculation:

$$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

sel's People

Contributors

oshalabydev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.