Add syntax sugar let f args... = ...

This commit is contained in:
백현웅 2022-02-23 02:45:36 +09:00
parent 74a4af9c33
commit c2ee352f1c
4 changed files with 15 additions and 1 deletions

4
ast.ml
View file

@ -61,6 +61,10 @@ let print ast =
| Nexternal e -> pr "(extern %s)" e
| Var v -> pr "%s" v
| Let (v, Nfunction (args, e)) ->
pr "(define (%s" v;
List.iter (pr " %s") args;
pr ") "; aux e; pr ")"
| Let (v, e) ->
pr "(define %s " v; aux e; pr ")"
| Letin (v, e, f) ->

View file

@ -329,6 +329,7 @@ and apply global env expr args =
begin match args with
| [] -> f
| args ->
(* bind arguments to variables *)
let rec aux e = function
| [], [] -> [], [], e
| vars, [] -> vars, [], e

View file

@ -177,9 +177,13 @@ and nothing seq =
and let_global seq =
let _, seq = ident "let" seq in
let id, seq = any_ident seq in
let args, seq = more any_ident seq in
let _, seq = token Token.Equal seq in
let e, seq = expr min_int seq in
Let (id, e), seq
(if args = []
then Let (id, e)
else Let (id, Nfunction (args, e))),
seq
(* expr := level
* | let_value

5
todo.md Normal file
View file

@ -0,0 +1,5 @@
# Todo
- macro
- implementing custom operator
- abstract stack machine & compiler