-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.mll
55 lines (53 loc) · 1.38 KB
/
lexer.mll
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
{
(* 補助的な変数、関数、型などの定義 *)
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 }
| "(" { LPAREN }
| ")" { RPAREN }
| "+" { PLUS }
| "-" { MINUS }
| "*" { TIMES }
| "/" { DIVIDE }
| "=" { EQUAL }
| "<>" { NOTEQUAL }
| "<" { LESS }
| "<=" { LESSEQUAL }
| ">" { GREATER }
| ">=" { GREATEREQUAL }
| "true" { TRUE }
| "false"{ FALSE }
| "if" { IF }
| "then" { THEN }
| "else" { ELSE }
| "let" { LET }
| "rec" { REC }
| "in" { IN }
| "fun" { FUN }
| "->" { ARROW }
| "try" { TRY }
| "with" { WITH }
| "shift"{ SHIFT }
| "reset"{ RESET }
| "control"{ CONTROL }
| "prompt" { PROMPT }
| "shift0" { SHIFT0 }
| "reset0" { RESET0 }
| "control0" { CONTROL0 }
| "prompt0" { PROMPT0 }
| digit+ (* 数字が1個以上 *)
{ NUMBER (int_of_string (Lexing.lexeme lexbuf)) }
| lower (alpha | digit) *
{ VAR (Lexing.lexeme lexbuf) }
| eof { EOF } (* 入力終了 *)
| _ { failwith ("unknown token: " ^ Lexing.lexeme lexbuf) }