Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/m3kPublic

Compiler code of m3k. m3k is a Lisp dialect that was written in TypeScript and compiles to JavaScript.

License

NotificationsYou must be signed in to change notification settings

obsfx/m3k

Repository files navigation

npm version

m3k is aLisp dialect that compiles toJavaScript. This repository contains the source code of the compiler. Project is still work in progress.

try:https://obsfx.github.io/m3k/

Usage

Installation

npm i -g m3k

Usage

m3k input.lisp

or

Installation

npm i m3k

Usage

importm3kfrom'm3k'consttokens=m3k.tokenize(source)constast=m3k.parse(tokens)consttransformAST=m3k.transform(ast)constcode=m3k.generate(transformAST)

or

<scriptsrc="m3k.js"></script><script>consttokens=m3k.tokenize(source)constast=m3k.parse(tokens)consttransformAST=m3k.transform(ast)constcode=m3k.generate(transformAST)</script>

Language Overview

;; Variables and data types                                 compiled output(define variable-name value)(define x5);; let x = 5;(define pet"Dog");; let pet = "Dog";(define negative-ten (-10));; let negativeTen = -10;(define number-list (list12345));; let numberList = [1, 2, 3, 4, 5];(define third-el-list (nth2 (list12345)));; let thirdElList = [1, 2, 3, 4, 5][2];(define dict-example (dict:name"Joe":surname"Dow"));; let dictExample = {name: "Joe", surname: "Dow"};(define dict-example-name (getval name dict-example));; let dictExampleName = dictExample.name;;; Function definition(define add (defun (ab) (+ a b)));; let add = (a, b) => (a + b);(define add-and-print (defun (ab);; let addAndPrint = (a, b) => ((() => {    (progn;;  console.log(a + b);        (print (+ a b));;  return a + b;        (+ a b))));; })());;; Reassigning variables(set! variable-name value)(set! r15);; r = 15;;; Pre-defined Methods(print"hello world");; console.log("hello world");(append arr1 (list123"list-data") arr2);; [...arr1, ...[1, 2, 3, "list-data"], ...arr2];(shift arr);; arr.shift();(unshift arr1);; arr.unshift(1);(pop arr);; arr.pop();(push arr1);; arr.push(1);(includes arr"thing");; arr.includes("thing");(concat arr1 arr2);; arr1.concat(arr2);(join arr",");; arr.join(", ");(slice"test-str"1);; "test-str".slice(1);(splice arr51);; arr.splice(5, 1);(map arr (defun (elementindex) (*2 element)));; arr.map((element, index) => (2 * element));(for-each arr (defun (elementindex);; arr.forEach((element, index) => (                  (print element index)));; console.log(element, index)));(filter arr (defun (elementindex) (< element index)));; arr.filter((element, index) => (element < index));(find arr (defun (elementindex) (< element index)));; arr.find((element, index) => (element < index));(reduce arr (defun (prevcurrent) (+ prev current))0);; arr.reduce((prev, current) => (prev + current), 0);;; Accessing JavaScript objects(getval property object)(getval body document);; document.body(define canvas ((getval create-element document)"canvas"));; let canvas = document.createElement("canvas");;; Comparison(!=55);; 5 !== 5;(=55);; 5 === 5;(>=55);; 5 >= 5;(<=55);; 5 <= 5;(%55);; 5 % 5;;; Conditional(if (=45);; (() => {    (print"equal");; if (4 === 5) { return console.log("equal");}    (print"not equal"));; else { return console.log("not equal");}})();

References

TODO

  • primitive types
  • variables
  • list
  • dict
  • methods
  • accessing objects
  • loops
  • functions
  • if statements
  • comment lines
  • return expression
  • error for reserved keywords
  • canvas utils
  • built-in draw methods
  • 3D transformations utils
  • keyboards input utils
  • documentation

About

Compiler code of m3k. m3k is a Lisp dialect that was written in TypeScript and compiles to JavaScript.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp