File tree Expand file tree Collapse file tree 4 files changed +32
-21
lines changed
Expand file tree Collapse file tree 4 files changed +32
-21
lines changed Original file line number Diff line number Diff line change @@ -21,9 +21,10 @@ type token =
2121 (* unknown *)
2222 | KWD of char
2323 (* special chars *)
24+ | EQUALS
25+ | ASSIGN
2426 | LEFT_PAREN
2527 | RIGHT_PAREN
26- | EQUALS
2728 | COMMA
2829 | SEMICOLON
2930 (* end of file *)
Original file line number Diff line number Diff line change 11open Core
22
33type token =
4+ (* commands *)
45 | DEF
56 | EXTERN
7+ (* control *)
68 | IF
79 | THEN
810 | ELSE
911 | FOR
1012 | IN
13+ (* operators *)
1114 | BINARY
1215 | UNARY
16+ (* var definition *)
1317 | VAR
18+ (* primary *)
1419 | IDENT of string
1520 | NUMBER of float
21+ (* unknown *)
1622 | KWD of char
23+ (* special chars *)
24+ | EQUALS
25+ | ASSIGN
1726 | LEFT_PAREN
1827 | RIGHT_PAREN
19- | EQUALS
2028 | COMMA
2129 | SEMICOLON
30+ (* end of file *)
2231 | EOF
2332[@@ deriving sexp ]
2433
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- | " =" { EQUALS }
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+ | " : =" { ASSIGN }
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
1516% token LEFT_PAREN
1617% token RIGHT_PAREN
1718% token COMMA
2829 | Some p -> p
2930% }
3031
31- % start < [`Expr of Ast.Expr.No_binop. func
32+ % start < [ `Expr of Ast.Expr.No_binop. func
3233 | `Extern of Ast. proto
3334 | `Def of Ast.Expr.No_binop. func
3435 | `Eof ]> toplevel
7576
7677 (* var
7778 * ::= 'var' identifier ('=' expression)? *)
78- var: name = IDENT ; e = option (EQUALS ; e = expr { e }) { (name, e) }
79+ var: name = IDENT ; e = option (ASSIGN ; e = expr { e }) { (name, e) }
7980
8081 (* unary
8182 * ::= primary
You can’t perform that action at this time.
0 commit comments