-
Notifications
You must be signed in to change notification settings - Fork 2
/
formula_lexer.mll
75 lines (58 loc) · 1.58 KB
/
formula_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{
open Lexing
open Formula_parser
let loc lexbuf = (lexeme_start_p lexbuf, lexeme_end_p lexbuf)
let buf = Buffer.create 1024
let newline lexbuf =
let pos = lexbuf.lex_curr_p in
lexbuf.lex_curr_p <-
{ pos with pos_lnum = pos.pos_lnum + 1; pos_bol = pos.pos_cnum }
exception Error of(Lexing.position * Lexing.position) * string
let raise_located loc e = raise (Error (loc, e))
}
let autChr = ['a'-'z' 'A'-'Z' '_' '<' '>' '=' '0'-'9' '+' '-' '*' '/' '\\' '&' '|' '!' '%' '^' '[' ']' '(' ')' '.']
let spaces = [' ' '\t' '\n']
rule token = parse
| spaces { token lexbuf }
| eof {EOF}
| "True" { TRUE }
| "False" { FALSE }
| "Call{" ((autChr| spaces)* as str) '}' { CALL(str) }
| "Ret{" ((autChr| spaces)* as str) '}' { RETURN(str) }
| '{' (autChr | spaces)+ '}' as str {PROP(str)}
| '(' { L_PAREN }
| ')' { R_PAREN }
(* Operator kinds *)
| "@N" {GENERAL}
| "@A" {ABSTRACT}
| "@P" {PAST}
(* Logic operators *)
| "==>" { IMPLIES }
| "<=>" { EQUIV }
| "OR" { OR }
| "AND" { AND }
| '!' { NOT }
(* CaRet operators *)
| 'G' { GLOBALLY }
| 'F' { FATALLY }
| 'U' { UNTIL }
| 'X' { NEXT }
| _ {
raise_located
(loc lexbuf)
(Format.sprintf "Illegal_character %s" (lexeme lexbuf))
}
(* {
raise_located
(loc lexbuf)
(Format.sprintf "Illegal_character %s\n" (lexeme lexbuf))
}*)
{
let parse c =
let lb = Lexing.from_channel c in
try
Formula_parser.main token lb
with
Invalid_argument _
| Parsing.Parse_error -> raise_located (loc lb) "Syntax error"
}