3

编程语言的执行

解释执行 https://github.com/coffee-js/languages/wiki/简化的解释器入门和编程语言了解
Machine Code http://en.wikipedia.org/wiki/Compiled_language

中间语言

JVM http://en.wikipedia.org/wiki/List_of_JVM_languages
CLI http://en.wikipedia.org/wiki/List_of_CLI_languages
Parrot http://trac.parrot.org/parrot/wiki/Languages
JavaScript https://github.com/jashkenas/coffeescript/wiki/List-of-languages-that-...
LLVM(个人收集) http://segmentfault.com/a/1190000002639770


解释执行

代码 -> 语法树 -> 遍历语法树

lisp(define a 1)
(print a)
(define (f a)
  (set a (+ a 1)))
  (return a)
(print (f a))

解析成 JSON:

[
  ["define", "a", "1"],
  ["print", "a"],
  ["define",
    ["f", "a"],
    ["set", "a", ["+", "a", "1"]],
    ["return", "a"]
  ],
  ["print", ["f", "a"]]
]

递归执行过程: eval(ast, env)


编译执行

类似解释执行, 但是输出结果是代码
对比生成 HTML, 动态生成 DOM, 静态编译 js 模版

Assembly
JVM Bytecode
LLVM IR (Intermediate Representation) http://www.stephendiehl.com/llvm/#llvm-introduction
Parrot VM
JavaScript
C


Cirru

直接生成(编辑)语法树, 没有明确语法

Parser: https://github.com/Cirru/cirru-parser
Editor: https://github.com/Cirru/cirru-editor
Writer: http://github.com/Cirru/cirru-writer

https://github.com/Cirru/cirru-mustache
https://github.com/Cirru/cirru-html
https://github.com/Cirru/cirru-html-js
https://github.com/Cirru/cirru-json
https://github.com/Cirru/cirru-script


CirruScript

用 Cirru 语法生成 JavaScript

http://repo.cirru.org/script/index.html
https://github.com/Cirru/script-console

--- JavaScript as IR

Mozilla JavaScript AST

https://github.com/estree/estree/blob/master/spec.md
https://speakerdeck.com/constellation/escodegen-and-esmangle-using-moz...
http://esprima.org/demo/parse.html

CoffeeScript2 -> CoffeeScript AST -> JavaScript AST -> JavaScript


Scirpus: Cirru -> ES6

Cirru AST -> ES6 AST -> ES5 AST -> JavaScript

https://github.com/babel/babel


题叶
17.3k 声望2.6k 粉丝

Calcit 语言作者