/JSOL

JSON programming language

Primary LanguagePythonApache License 2.0Apache-2.0

JSOL: JavaScript Object Language

JSOL is an interpreted language represented by JSON. Since any JSOL program
is completely written in JSON, its data structures and functions can be
represented (and edited) in any language that has a JSON parser and JSOL
interpreter. This allows for easy passing of complete programs between
applications.

PSOL is a cleaner syntax for JSOL. A PSOL program can be parsed into JSOL
using parser.py. Examples of PSOL can be found in the examples/psol
directory, or in test_data/psol.

Check out http://jsol.org for an online JSOL/PSOL playground.

This is the very first version, so there are many improvements to be made.


Features

 - Closures
 - First class functions
 - String, list, number, dictionary, null, and function types
 - Fully representable in JSON.
 - Easily extendable with modules (see examples/file_reader.jsol).


Syntax

   Basic
    - '{"a": 5}'                     -> assignment
    - '"add": {...}'                 -> function definition
    - '["add", "a", "b", "a"]'       -> function call
    - '{"lit": "hello"}'             -> string literal
    - '["import", {"lit": "file"}]'  -> import a module

   Lists
    - '{"lit": [1, 2, 3]}'           -> list literal
    - '["l", 0]'                     -> get first element in list
    - '["l", 0, 5]'                  -> set first element in list to be 5
    - '["del", "l", 0]'              -> delete and return first element in list
    - '["ins", "l", 0, 5]'           -> insert 5 into the beginning of the list

   Dictionaries
    - '{"lit": {"a": 5, "b": 2}}'    -> dictionary literal
    - '["d", {"lit": "a"}]'          -> get the value with the key "a"
    - '["d", {"lit": "a"}, 5]'       -> set "a" to be 5 in the dictionary

   If block
    - '["if",                        |
          <cond>, [...],             |
          <cond>, [...],             |
          ...                        |
          [...]                      |
       ]'                            -> if/else


Examples

The examples/jsol directory has some example programs.
Run examples by typing 'jsol.py examples/jsol/<name_of_example>'

   - fib.jsol - outputs the Fibonacci sequence using a closure
   - recursive.jsol - an example of a recursive function
   - quick_sort.jsol - an example of sorting a list by passing in a compare
     function
   - file_reader.jsol - prompts the user for a filename and then prints the
     file to the screen. Uses the 'file' module.
   - passer.py - ./passer.py (in main directory) illustrates passing a JSOL
     program between applications
   - editor.py - ./editor.py shows how a JSOL program can be edited on the fly

Most of these examples also have a PSOL version in examples/psol.
Run these by typing 'parser.py examples/psol/<name_of_example>'


Testing

Run tests using 'run_tests.sh'


Future

 - Better error handling/messages.
 - More examples.
 - Documentation.
 - Porting into other languages (probably starting with JavaScript).

Created by Clark DuVall http://clarkduvall.com