A "Basic-to-Lisp" compiler. But Basic is not real Basic, and Lisp is not real Lisp.

Overview

Basic2Lisp

A "Basic-to-Lisp" compiler.
But Basic is not real Basic, and Lisp is not real Lisp.

Syntax

Print-Sth

Put some-value to standard output.

PRINT value;
(print value)

Comment

' here are the comments
; here are the comments

Value

' Simple Value
114514
' Operator Expression
(1919 + 810)
' Function
abs(-10)
; Simple Value
114514
; Operator Expression
(+ 1919 810)
; Function
(abs -10)

BASIC value cannot exist as a statement, but with a semicolon (;).

1;

Complex Expression

In this basic project, we use ( and ) to express every complex expressions.

LET complex_expr = (((1 + 2) * 3) - (4 / 5));

So that, we do not need to consider operator priority and left recursion.

Value-Binding : define & LET

Bind some value to a fixed name.

LET homo = 114514;
PRINT homo;
(define homo 114514)
(print homo)

Unlike basic, we can use define to name a function.

(define show print)
(show 1919810)

Function : DEF & lambda

Construct a function.

DEF id(x)
    RETURN x;
END
(define id
    (lambda (x) x))

Unlike basic, we can construct a procedure(function) without name. It can also used as usual.

(+ 
    ((lambda (x) (* x x)) 100) 
    104514)

Demo

Fibonacci

DEF fib(x)
    IF (x < 2) THEN
        RETURN 1;
    ELSE
        RETURN (fib((x - 1)) + fib((x - 2)));
    END
END
(define fib
    (lambda (x)
        (if (< x 2)
            1
            (+ (fib (- x 1)) (fib (- x 2))))))

Square Root

' sqrt
DEF sqrt(x)
    DEF abs(x)
        IF (x > 0) THEN
            RETURN x;
        ELSE
            RETURN (0 - x);
        END
    END

    DEF good_enough(g,w)
        RETURN (abs(((g * g) - w)) < (g / 100000));
    END

    DEF guess(g,w)
        IF good_enough(g,w) THEN
            RETURN g;
        ELSE
            RETURN guess(improve(g,w),w);
        END
    END

    DEF improve(g,w)
        RETURN ((g + (w / g)) / 2);
    END

    RETURN guess(1,x);
END

PRINT sqrt(1919810);
; sqrt
(define sqrt
    (lambda (x) 
        (define abs (lambda (x) (if (> x 0) x (- x))))
        (define good-enough?
            (lambda (g w)
                (< (abs (- (* g g) w)) (/ g 100000))))
        (define guess
            (lambda (g w)
                (if (good-enough? g w)
                    g
                    (guess (improve g w) w))))
        (define improve
            (lambda (g w)
                (/ (+ g (/ w g)) 2)))
        (guess 1 x)))

(print (sqrt 1919810))

Cons | Car | Cdr

DEF cons(x,y)
    DEF temp(op)
        RETURN op(x,y);
    END
    RETURN temp;
END

DEF car(cons)
    DEF temp(x,y)
        RETURN x;
    END
    RETURN cons(temp);
END

' (1,2) => 1
car(cons(1,2));
(define cons
    (lambda (a d)
        (lambda (op) (op a d))))

(define car
    (lambda (cons)
        (cons (lambda (a d) a))))

; (1,2) => 1
(car (cons 1 2))

Others

Shortcut keys

  • Ctrl + F9 : Compile
  • Ctrl + F10 : Run
  • Ctrl + F11 : Clear
  • Ctrl + S : Save
You might also like...

Plain JavaScript version of jQuery's slideToggle(), slideDown(), & slideUp(), but does not use display: none.

dom-slider It works like jQuery's slideToggle(), slideDown(), & slideUp(), but does not use display: none. Uses CSS3 transitions and element.scrollHei

Dec 27, 2022

A markdown parser and compiler. Built for speed.

Marked ⚡ built for speed ⬇️ low-level compiler for parsing markdown without caching or blocking for long periods of time ⚖️ light-weight while impleme

Jan 7, 2023

Lightweight and versatile build tool based on the esbuild compiler

Lightweight and versatile build tool based on the esbuild compiler

Estrella is a lightweight and versatile build tool based on the fantastic esbuild TypeScript and JavaScript compiler. Rebuild automatically when sourc

Jan 2, 2023

A Laravel Blade parser, compiler, and static analyzer written in TypeScript.

Blade Parser This library provides a Laravel Blade parser written in TypeScript. In addition to being able to parse Blade template files, this library

Jan 4, 2023

An oversimplification of the TypeScript Compiler API for defining and generating source files.

An oversimplification of the TypeScript Compiler API for defining and generating source files.

Tanu 🦝 A simplified abstraction of the TypeScript Compiler API for defining and generating source files. Tanu 🦝 Why? What does Tanu mean? 🦝 How do

Oct 29, 2022

A Compiler npm Package.

vcompiler 🎉 Version 1.x is live ! 🎉 Introducation It is the npm package for the compilation of the code. Currently it supports the following program

May 30, 2022

This is a library that makes it possible to change the configuration values of the Remix compiler (esbuild).

💽 remix-esbuild-override ⚠️ While I believe you will most likely get a lot of benefit from using this library, it can sometimes destroy your product.

Dec 22, 2022

The full power of the Go Compiler directly in your browser, including a virtual file system implementation. Deployable as a static website.

The full power of the Go Compiler directly in your browser, including a virtual file system implementation. Deployable as a static website.

Static Go Playground Features Full Go Compiler running on the browser. Supports using custom build tags. Incremental builds (build cache). Supports mu

Jun 16, 2022
JIT Compiler is a open source online code compiler. You can run more than 40+ most popular programming languages in your browser just-in-time using jitcompiler.

JIT Compiler is a open source online code compiler. You can run more than 40+ most popular programming languages in your browser just-in-time using jitcompiler.

Rajkumar Dusad 36 Jan 5, 2023
our features are few but we provide the best and it is not uncommon to find in other npmjs

hikki-me our features are few but we provide the best and it is not uncommon to find in other npmjs Installation Install hikki-me with npm npm install

(Anto) 10 Jul 10, 2022
A dad joke is a short joke, typically a pun, presented as a one-liner or a question and answer, but not a narrative

A dad joke is a short joke, typically a pun, presented as a one-liner or a question and answer, but not a narrative. Many dad jokes may be considered anti-jokes, deriving humor from an intentionally not funny punchline. daddy-jokes is an npm package that returns a dad joke when implemented.

Abir Bhattacharya 5 Oct 23, 2022
An interactive Bitcoin tutorial for orange-pilled beginners. Illustrates technical Bitcoin concepts using JavaScript and some Bitcoin Core RPC commands. Programming experience is helpful, but not required.

Try Bitcoin Try Bitcoin is an interactive Bitcoin tutorial inspired by and forked from Try Regex, which is inspired by Try Ruby and Try Haskell. It il

Stacie Waleyko 33 Nov 25, 2022
A Browser extension that not only makes your browsing experience safe but makes it optimized

Sia Sia is a browser extension that not only makes your browsing experience safe but makes it optimized Table of Contents About The Project Built With

Arun Govind M 14 Feb 23, 2022
It's not butter, but it's root.

margerine Episode 2: Revenge of the ¯\_(ツ)_/¯ margerine is a root exploit and adb enabler for the DJI Air Unit (wm150), Caddx Vista (lt150), FPV Goggl

fpv.wtf 183 Dec 24, 2022
WhyProfiler is a CPU profiler for Jupyter notebook that not only identifies hotspots but can suggest faster alternatives.

Introduction WhyProfiler is a CPU profiler for Jupyter notebook that not only identifies hotspots but can suggest faster alternatives. It is powered b

Robusta 44 Dec 5, 2022
🪐 The IPFS gateway for NFT.Storage is not "another gateway", but a caching layer for NFTs that sits on top of existing IPFS public gateways.

nftstorage.link The IPFS gateway for nft.storage is not "another gateway", but a caching layer for NFT’s that sits on top of existing IPFS public gate

NFT.Storage 37 Dec 19, 2022
BttrLazyLoading is a Jquery plugin that allows your web application to defer image loading until images are scrolled to but not only

BttrLazyLoading.js BttrLazyLoading is a Jquery plugin that allows your web application to defer image loading until images are scrolled to but not onl

Julien Renaux 410 Dec 14, 2022