-
Notifications
You must be signed in to change notification settings - Fork 4
/
grammar.py
executable file
·77 lines (73 loc) · 1.06 KB
/
grammar.py
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
grammar = {
"tokens" : [
{
"name" : "let",
"regex" : r"(\A|\b)let"
},
{
"name" : "single_line_comment",
"regex" : r"//(.*)$"
},
{
"name" : "multi_line_comment_start",
"regex" : r"/[*]+"
},
{
"name" : "multi_line_comment_end",
"regex" : r"[*]+/"
},
{
"name" : "EOL",
"regex" : r";"
},
{
"name" : "ma_add",
"regex" : r"\+"
},
{
"name" : "ma_subtract",
"regex" : r"\-"
},
{
"name" : "ma_multiply",
"regex" : r"\*"
},
{
"name" : "if",
"regex" : r"\bif\b"
},
{
"name" : "assign",
"regex" : r"\s+=\s+"
},
{
"name" : "equals",
"regex" : r"\s==\s"
},
{
"name" : "start_apply",
"regex" : r"\("
},
{
"name" : "end_apply",
"regex" : r"\)"
},
{
"name" : "arglist_separator",
"regex" : r","
},
{
"name" : "constant_string",
"regex" : r"\".*\""
},
{
"name" : "constant_numerical",
"regex" : r"[0-9]+",
"transform" : (lambda val: int(val))
},
{
"name" : "identifier",
"regex" : r"(\s+|\w|^)(?!let)(?!if)[a-z]+(\s*)"
}
]
}