-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.mly
60 lines (49 loc) · 845 Bytes
/
parser.mly
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
%{
open Ast
open Identifier
open Lexing
%}
%token LPAREN
%token RPAREN
%token <int> NUMBER
%token <bool> BOOLEAN
%token <string> SYMBOL
%token DOT
%token QUOTE
%token EOF
%start main
%type <Ast.datum list> main
%type <Ast.datum> datum
%%
main:
| datum main { $1 :: $2 }
| EOF { [] }
;
datum:
| literal { Atom ($1) }
| symbol { Atom ($1) }
| cons { $1 }
| nil { $1 }
| quoted { $1 }
;
literal:
| NUMBER { Integer $1 }
| BOOLEAN { Boolean $1 }
nil:
| LPAREN RPAREN { Nil }
;
symbol:
| SYMBOL { Identifier (identifier_of_string $1) }
;
cons:
| LPAREN datum cons_tail { Cons ($2, $3) }
;
cons_tail:
| RPAREN { Nil }
| datum cons_tail { Cons ($1, $2) }
| DOT datum RPAREN { $2 }
;
quoted:
| QUOTE datum { Cons (Atom (Identifier (identifier_of_string "quote")),
Cons ($2, Nil)) }
;