Skip to content

asmarcz/TinyLISP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TinyLISP

Build using Intellij Idea Scala plugin or sbt from the command line.

Building a Fat JAR

Running

sbt assembly

will produce a Fat JAR. See output for destination directory.

Run an example:

java -jar TinyLISP-assembly-0.1.0-SNAPSHOT.jar ../../examples/factorial.lsp

API Usage

// construct parser
val result: List[Item] = rep(whitespace(item()))(code) match
  case Accept(value, rem) => // parser accepted
    if (rem.forall(_.isWhitespace)) { // all input was read
      val instructions = CompilationManager().compile(value)
      val runtime = Runtime(
        mutable.Stack.from(instructions), // code stack
      )
      runtime.run()
      runtime.getResult // return stack as a List
    }
    else throw IllegalArgumentException(s"Unexpected input at the end: '$rem'")
  case Reject(_) => throw IllegalArgumentException()

Supported functions

Binary operations: +, -, *, /, <, >, =, cons.

Unary operations: car, cdr.

Built-ins: define, let, lambda, if, cons dot (.).

(= (cons a b) (a . b))

(define (funName arg1 arg2 ...)
    body)

(let (var1 var2) (val1 val2)
    body)

(lambda (arg1 arg2 ...)
    body)

(if cond
    trueBranch
    falseBrach)

About

A tiny LISP implementation in Scala as an SECD virtual machine.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages