-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer.mll
More file actions
52 lines (50 loc) · 1.33 KB
/
lexer.mll
File metadata and controls
52 lines (50 loc) · 1.33 KB
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
{
(* 補助的な変数、関数、型などの定義 *)
open Parser
}
(* 正規表現の略記 *)
(* [...] の中は character '...' でなくてはならない *)
let space = [' ' '\t' '\n' '\r']
let digit = ['0'-'9']
let lower = ['a'-'z']
let upper = ['A'-'Z']
let alpha = lower | upper
rule token = parse
| space+ { token lexbuf } (* スペースは読み飛ばす *)
| "(*" [^ '\n']* "\n" (* ( * から行末まではコメント *)
{ token lexbuf }
| "+" { PLUS }
| "-" { MINUS }
| "*" { TIMES }
| "=" { EQUAL }
| "<" { LESS }
| ">" { GREATER }
| "true" { TRUE }
| "false" { FALSE }
| "(" { LPAREN }
| ")" { RPAREN }
| "if" { IF }
| "then" { THEN }
| "else" { ELSE }
| "let" { LET }
| "in" { IN }
| "fun" { FUN }
| "->" { ARROW }
| "rec" { REC }
| "[" { LBRACKET }
| "]" { RBRACKET }
| "::" { CONS }
| "match" { MATCH }
| "with" { WITH }
| "|" { BAR }
| ";" { SEMI }
| "/" { DIV }
| "raise" { RAISE }
| "Error" { ERROR }
| "try" { TRY }
| digit+ (* 数字が1個以上 *)
{ NUMBER (int_of_string (Lexing.lexeme lexbuf)) }
| lower (lower | upper | digit)*
{ VAR (Lexing.lexeme lexbuf) }
| eof { EOF } (* 入力終了 *)
| _ { failwith ("unknown token: " ^ Lexing.lexeme lexbuf) }