Lisp interpreter implemented with C++

You can find the source code here

Architecture

  • Tokenizer
  • Text Parser
  • BuiltIn
  • Environment
  • AST
  • Macro Compiler
  • Evaluator

Architecture

Features

true*==>orlistrm_headconsfoldl
false/<=defifpush_backrm_tailmaxmap
+%>=setwhileheadnth_elementmin
-!<andfunctailsizefilter

Sample of Abstract Syntax Tree

Fibonacci sequence recuesive version
(function fib (n) 
  (if 
    (< n 2) 
    n 
    (+ 
      (fib (- n 1)) 
      (fib (- n 2))
    )
  )
)

Sample of Abstract Syntax Tree

Sample Results

Fibonacci sequence iterative version
(def a (list 0 1 1))
(function fib(n) 
  (while 
    (< (size a) n)  
      (push_back a  
      (+
        (nth_element(- (size a) 1) a)
        (nth_element(- (size a) 2) a)
      )
    )
  )
)

result of iterative fibonacci sequence

Function and Higher Order Function

Example of the filter function.

(def a (list 1 2 3 4))
(function even (x)
  (if
    (== (% x 2) 0)
    true
    false
   )
)
(filter even a)

result of filter

Example of foldl function.

(def a (list 1 2 3 4))
(function sum(x y) (+ x y))
(foldl sum 10 a)

result of fold

You can also implement your own logic for map, foldl and filter function.

Function Overloading

Example of sum function overloading.

(function add (a b) (+ a b))
(function add (a b c) (+ a b c))

result of function overloading

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值