Code Monkey home page Code Monkey logo

slisp's Introduction

example workflow

A simple lisp interpreter

General workflow:

stdin: (foo (bar x) (baz x y z) q) ===> lex:sexp()
                                   ===> ast:ast()
                                   ===> ast:intrp()
                                   ===> heap {foo: "xyz", bar: "pqr", q: "qwerty"}.

Consists of the following components:

  • lex: parses parentheses-tree into {List|Atom}-tree:
(foo 1 (bar 2)) --> List([Atom("foo"),
                          Atom("1"),
                          List([Atom("bar"), Atom("2")])]).
  • ast: converts {List|Atom}-tree into {Seq|While|If|Var|...}-tree:
List([List([Atom('let'), Atom('b'), Atom('0')]),
      List([Atom('let'), Atom('a'), Atom('10'),
      List([Atom('while'), Atom('a'),
                           List([List([Atom('let'), Atom('a'),
                                 List([Atom('-'), Atom('a'), Atom('1')])]),
                                 List([Atom('let'), Atom('b'),
                                 List([Atom('+'), Atom('b'), Atom('2')])])])])])]).
|
V
Seq([Assign('b', Const(0)),
     Assign('a', Const(10)),
     While(Var('a'),
         Seq([Assign('a', Op('-', Var('a'), Const(1))),
              Assign('b', Op('+', Var('b'), Const(2)))]))]).
  • ast: intrp() calculates variable values in the heap.
  • features:
    • strings,
    • printf(),
    • functions,
    • lists (implement on top of structs),
    • structs,
    • unary operators like `not',
    • functions as first order citizens (funcall, &rest, #'),
    • lambda,
    • curry, closures,
    • function composition,
    • fds/stdin/stdout,
    • sscanf()-ish thing str.split() alike parser + str/int/float,
    • efficient containers based on pythonish lists, dicts, arrays,
    • imports/modules (cat is sufficient),
    • more robustness, assertiveness, etc,
    • ffi, at least extendable code.
  • uses python3.10 mostly to try patternmatching.
  • WARN: has bugs in favour of simplicity.
  • UPD 7/01/22: prototype is almost finished, sscanf()-ish thing could be the last missing part.
  • UPD 9/01/22: prototype is almost finished, will try not to work more on this.
  • UPD 10/01/22: produced calc-lisp language written in slisp. That's it folks.

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.