File tree Expand file tree Collapse file tree 4 files changed +21
-32
lines changed
Expand file tree Collapse file tree 4 files changed +21
-32
lines changed Original file line number Diff line number Diff line change @@ -21,10 +21,9 @@ type token =
2121 (* unknown *)
2222 | KWD of char
2323 (* special chars *)
24- | EQUALS
25- | ASSIGN
2624 | LEFT_PAREN
2725 | RIGHT_PAREN
26+ | EQUALS
2827 | COMMA
2928 | SEMICOLON
3029 (* end of file *)
Original file line number Diff line number Diff line change 11open Core
22
33type token =
4- (* commands *)
54 | DEF
65 | EXTERN
7- (* control *)
86 | IF
97 | THEN
108 | ELSE
119 | FOR
1210 | IN
13- (* operators *)
1411 | BINARY
1512 | UNARY
16- (* var definition *)
1713 | VAR
18- (* primary *)
1914 | IDENT of string
2015 | NUMBER of float
21- (* unknown *)
2216 | KWD of char
23- (* special chars *)
24- | EQUALS
25- | ASSIGN
2617 | LEFT_PAREN
2718 | RIGHT_PAREN
19+ | EQUALS
2820 | COMMA
2921 | SEMICOLON
30- (* end of file *)
3122 | EOF
3223[@@ deriving sexp ]
3324
Original file line number Diff line number Diff line change 1616 | newline { read lexbuf }
1717 | " def" { DEF }
1818 | " extern" { EXTERN }
19- | " if" { IF }
20- | " then" { THEN }
21- | " else" { ELSE }
22- | " for" { FOR }
23- | " in" { IN }
24- | " binary" { BINARY }
25- | " unary" { UNARY }
26- | " var" { VAR }
27- | id { IDENT (Lexing. lexeme lexbuf) }
28- | float { NUMBER (float_of_string (Lexing. lexeme lexbuf)) }
29- | " : =" { ASSIGN }
30- | " (" { LEFT_PAREN }
31- | " )" { RIGHT_PAREN }
32- | " ," { COMMA }
33- | " ;" { SEMICOLON }
19+ | " if" { IF }
20+ | " then" { THEN }
21+ | " else" { ELSE }
22+ | " for" { FOR }
23+ | " in" { IN }
24+ | " binary" { BINARY }
25+ | " unary" { UNARY }
26+ | " var" { VAR }
27+ | id { IDENT (Lexing. lexeme lexbuf) }
28+ | float { NUMBER (float_of_string (Lexing. lexeme lexbuf)) }
29+ | " =" { EQUALS }
30+ | " (" { LEFT_PAREN }
31+ | " )" { RIGHT_PAREN }
32+ | " ," { COMMA }
33+ | " ;" { SEMICOLON }
3434 (* '#' marks the beginning of a comment *)
3535 | " #" { read_comment lexbuf }
36- | _ { KWD (Lexing. lexeme_char lexbuf 0 ) }
37- | eof { EOF }
36+ | _ { KWD (Lexing. lexeme_char lexbuf 0 ) }
37+ | eof { EOF }
3838
3939 and read_comment =
4040 parse
Original file line number Diff line number Diff line change 1212% token < float > NUMBER
1313% token < char > KWD
1414% token EQUALS
15- % token ASSIGN
1615% token LEFT_PAREN
1716% token RIGHT_PAREN
1817% token COMMA
2928 | Some p -> p
3029% }
3130
32- % start < [ `Expr of Ast.Expr.No_binop. func
31+ % start < [`Expr of Ast.Expr.No_binop. func
3332 | `Extern of Ast. proto
3433 | `Def of Ast.Expr.No_binop. func
3534 | `Eof ]> toplevel
7675
7776 (* var
7877 * ::= 'var' identifier ('=' expression)? *)
79- var: name = IDENT ; e = option (ASSIGN ; e = expr { e }) { (name, e) }
78+ var: name = IDENT ; e = option (EQUALS ; e = expr { e }) { (name, e) }
8079
8180 (* unary
8281 * ::= primary
You can’t perform that action at this time.
0 commit comments