File tree Expand file tree Collapse file tree 5 files changed +85
-0
lines changed Expand file tree Collapse file tree 5 files changed +85
-0
lines changed Original file line number Diff line number Diff line change
1
+ CFG example:
2
+ %start program
3
+
4
+ Program:
5
+ | Interfaces (signature)
6
+ | implementation (after end)
7
+ | eof
8
+
9
+ Interface:
10
+ |stroage
11
+ |map
12
+ |event
13
+ |method
14
+
15
+ Implementation:
16
+ |constructor
17
+ |method
18
+
19
+ Constructor:
20
+ | storage
21
+ |returns
22
+
23
+ Method:
24
+ |guard
25
+ |storage
26
+ |effects
27
+ |returns
28
+
Original file line number Diff line number Diff line change
1
+ {open Parser }
2
+
3
+ let digits = ['0' - '9' ]
4
+ let letter = ['a' - 'z' 'A' - 'Z' ]
5
+
6
+ rule token = parse
7
+ [' ' '\t' '\r' '\n' ] { token lexbuf }
8
+ | '-' {comment 1 lexbuf} (* comment *)
9
+ | " /-" {multicomment 1 lexbuf} (* multiple comment *)
10
+ | '(' { LPAREN }
11
+ | ')' { RPAREN }
12
+ | '{' { LBRACE }
13
+ | '}' { RBRACE }
14
+ | '[' { LBRACK }
15
+ | ']' { RBRACK }
16
+ | ';' { SEMI }
17
+ | ':' { COLON }
18
+ | "->" { ARROW }
19
+ | "|->" { PASSIGN }
20
+ | '=' { ASSIGN }
21
+ | " end" { END }
22
+ | " storage" { STROAGE }
23
+ | " event" { EVENT }
24
+ | " map" { MAP }
25
+ | " signature" { SIGNATURE }
26
+ | " UInt" { UINT }
27
+ | " of" { OF }
28
+ | " Address" { ADDRESS }
29
+ | ':' { COLON }
30
+ | " True" { BLIT (true ) }
31
+ | " False" { BLIT (false ) }
32
+ | " Bool" { BOOL }
33
+ | " method" { METHOD }
34
+ | " constructor" { CONSTRUCTOR }
35
+ | " Env" { ENVIRONMENT }
36
+ | '.' { POINT }
37
+ | " ()" { UNIT }
38
+ | " ==" { EQ }
39
+ | " !=" { NEQ }
40
+ | " guard" { GUARD }
41
+ | " effects" { EFFECTS }
42
+ | " logs" { LOGS }
43
+ | " returns" { RETURNS }
44
+ | " >" { LGT }
45
+ (* IF ? *)
46
+ (* WHILE ? *)
47
+ | digit+ as lem { LITERAL (int_of_string lem) }
48
+ | letter (digit | letter | '_' )* as lem { ID (lem) }
49
+ | eof { EOF }
50
+
51
+ and comment lvl = parse
52
+ " \n " { if lvl = 1 then token lexbuf else comment (lvl - 1 ) lexbuf }
53
+ | _ { comment lvl lexbuf }
54
+
55
+ and multicomment lvl = parse
56
+ " -/" { if lvl = 1 then token lexbuf else comment (lvl - 1 ) lexbuf }
57
+ | _ { multicomment lvl lexbuf }
You can’t perform that action at this time.
0 commit comments