forked from ermine/sulci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcalc_lexer.mll
53 lines (49 loc) · 1.67 KB
/
pcalc_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
{
(*
* (c) 2004-2010 Anastasia Gornostaeva
*)
open Pcalc
}
let digit = ['0'-'9']
rule token = parse
| [' ' '\t'] { token lexbuf }
| digit+
| "." digit+
| digit+ "." digit+
| digit+ ("." digit)* ("e"|"E")('-'|'+')? digit+ as num
{ NUM (float_of_string num) }
| '0' ('x'|'X') ['A'-'F' 'a'-'f' '0'-'9']+ as num
{ NUM (float_of_string num) }
| '0' ['b' 'B'] ['0' '1']+ as num
{ NUM (float_of_int (int_of_string num)) }
| '0' ['o' 'O'] ['0'-'8']+ as num
{ NUM (float_of_int (int_of_string num)) }
| '+' { PLUS }
| '-' { MINUS }
| '*' { MUL }
| '/' { DIVIDE }
| '%' { MOD }
| '^' { CARET }
| 'n' { UMINUS }
| "sqrt" { SQRT }
| "exp" { EXP }
| "log" { LOG }
| "log10" { LOG10 }
| "cos" { COS }
| "sin" { SIN }
| "tan" { TAN }
| "asoc" { ACOS }
| "asin" { ASIN }
| "atan" { ATAN }
| "atab2" { ATAN2 }
| "cosh" { COSH }
| "sinh" { SINH }
| "tanh" { TANH }
| "ceil" { CEIL }
| "floor" { FLOOR }
| "fact" { FACT }
| "fib" { FIB }
| "max_float" { MAX_FLOAT }
| ['p' 'P'] ['i' 'I'] { PI }
| _ { token lexbuf }
| eof { EOL }