Skip to content

Commit 399a9ca

Browse files
committed
scanner code, parser idea
1 parent 05933f8 commit 399a9ca

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

my_designIdea

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+

src/ast.ml

Whitespace-only changes.

src/parser.mly

Whitespace-only changes.

src/scanner.mll

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 }

0 commit comments

Comments
 (0)