-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSyntax.pyLRp
79 lines (57 loc) · 1.6 KB
/
Syntax.pyLRp
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
# -*-python-*-
import AST
%lexer
\n\s* NEWLINE
[ \t]+ %restart
;.*\n NEWLINE
[a-zA-Z][a-zA-Z0-9_]* ID
[a-zA-Z][a-zA-Z0-9_]*: LABEL
0x[0-9a-zA-Z]+ HEX
%[rR][0-9a-fA-F] REG
%parser
uberdoc:
onewline doc newline
doc:
line:
self.doc.AddInstr($1.sem)
LABEL line:
self.doc.DefineLabel($1.sem[:-1])
self.doc.AddInstr($2.sem)
doc newline LABEL line:
self.doc.DefineLabel($3.sem[:-1])
self.doc.AddInstr($4.sem)
doc newline line:
self.doc.AddInstr($3.sem)
LABEL:
self.doc.DefineLabel($1.sem[:-1])
doc newline LABEL:
self.doc.DefineLabel($3.sem[:-1])
directive:
pass
doc newline directive:
pass
LABEL directive:
self.doc.DefineLabel($1.sem[:-1])
doc newline LABEL directive:
self.doc.DefineLabel($3.sem[:-1])
onewline:
%empty
onewline NEWLINE
newline:
newline NEWLINE
NEWLINE
directive:
".const" ID HEX: self.doc.DefineConst($2.sem, int($3.sem, base=16))
".address" HEX: self.doc.SetIP(int($2.sem, base=16))
line:
ID: $$.sem = self.doc.BuildInstr($1.sem.lower(), [])
ID paramlist: $$.sem = self.doc.BuildInstr($1.sem.lower(), $2.sem)
paramlist:
ID: $$.sem = [AST.Name($1.sem)]
REG paramlist1: $$.sem = [AST.Reg($1.sem)] + $2.sem
paramlist1:
%empty: $$.sem = []
"," HEX: $$.sem = [AST.Lit(int($2.sem, base=16))]
"," REG: $$.sem = [AST.Reg($2.sem)]
"," "(" REG ")": $$.sem = [AST.RegRef($3.sem)]
"," ID: $$.sem = [AST.Name($2.sem)]