-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmulexer.mll
91 lines (80 loc) · 3.08 KB
/
mulexer.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
(**************************************************************************)
(* *)
(* Cubicle *)
(* *)
(* Copyright (C) 2011-2015 *)
(* *)
(* Sylvain Conchon and Alain Mebsout *)
(* Universite Paris-Sud 11 *)
(* *)
(* *)
(* This file is distributed under the terms of the Apache Software *)
(* License version 2.0 *)
(* *)
(**************************************************************************)
{
open Options
open Lexing
open Muparser
let print_mu = ref debug
let string_buf = Buffer.create 1024
exception Lexical_error of string
let rule_trace = ref ""
}
let newline = '\n'
let space = [' ' '\t' '\r']
let integer = ['0' - '9'] ['0' - '9']*
let ident = ['a'-'z' 'A'-'Z']['a'-'z' 'A'-'Z' '0'-'9' '_' '.']*
let str = [^ '"']*
let var = ident ('[' (ident | integer) ']')*
rule token = parse
| "State" space* (integer as n) ":" newline
{ Muparser_globals.new_state ();
Muparser.state state lexbuf;
STATE (int_of_string n) }
| "Progress Report:" newline
{ print_mu := !print_mu || not quiet; token lexbuf }
| "Invariant \"" (str as s) "\" failed." newline
{ Muparser_globals.new_state ();
Format.printf "\n@{<fg_red>Error trace@}:@[<hov> ";
rule_trace := s;
Muparser.error_trace error lexbuf;
token lexbuf }
| eof
{ EOF }
| newline
{ if !print_mu then print_newline (); token lexbuf }
| _ as c
{ if !print_mu then print_char c; token lexbuf }
and state = parse
| newline space* newline
{ ENDSTATE }
| space+ | newline
{ state lexbuf }
| (var as v) ':' (ident | integer as x)
{ AFFECTATION (v, x) }
(* Less efficient to generate tokens *)
(* | ident as id *)
(* { (\* Format.printf "lexing %s@." id; *\) IDENT id } *)
(* | integer as n *)
(* { (\* Format.printf "lexing %s@." n; *\) INT n } *)
(* | '[' { LEFTSQ } *)
(* | ']' { RIGHTSQ } *)
(* | ':' { COLON } *)
| _ as c
{ raise (Lexical_error
("illegal character in murphi state: " ^ String.make 1 c)) }
and error = parse
| "----------"
{ ENDSTATE }
| "End of the error trace."
{ ENDTRACE !rule_trace }
| ident space+ (ident as t)
((',' space* ident ':' ident)* as v) space+ "fired." newline
{ STEP (t, v) }
| (var as v) ':' (ident | integer as x)
{ AFFECTATION (v, x) }
(* | space+ | newline *)
(* { error lexbuf } *)
| _ (* as c *)
{ error lexbuf }