-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrainf.fasml
More file actions
205 lines (166 loc) · 2.69 KB
/
Copy pathbrainf.fasml
File metadata and controls
205 lines (166 loc) · 2.69 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
MOV $mem_size 1024
IF NEQ $ARGC 2
[
IF NEQ $ARGC 3
[
PRT Usage: $0 <file> $LBR
PRT optional: memory-size, default: $mem_size
PRT $RBR $ENDL
BYE 1
]
]
MOV $file $1
FREAD $buf $file $except
IF NEQ $except 0
[
PRT $0
PRT : Error: $file
PRT : No such file $ENDL
BYE 1
]
IF EQL $ARGC 3
[
MOV $mem_size $2
]
CALL len $buf
RECV $len
MOV $line_count 1
MOV $char_count 1
MOV $i 0
STR $buf
MOV $tos -1
> $loop
IF LSS $i $len
[
ARRV $c $buf $i
IF SEQL $c $ENDL
[
ADD $line_count $line_count 1
INT $line_count $line_count
MOV $char_count 1
JMP $endif
]
IF SEQL $c $LBR
[
FCALL $push
JMP $endif
]
IF SEQL $c $RBR
[
IF EQL $tos -1
[
PRT $0
PRT : Error: $file
PRT : Unmatched '
PRT $RBR
PRT ' at line $line_count
PRT , char $char_count $ENDL
BYE 1
]
FCALL $pop
ARR $pairs $i $temp
ARR $pairs $temp $i
]
> $endif
ADD $i $i 1
INT $i $i
JMP $loop
]
IF NEQ $tos -1
[
PRT $0
PRT : Error: $file
PRT : Unmatched '
PRT $LBR
PRT ' at line $line_count
PRT , char $char_count $ENDL
BYE 1
]
MOV $i 0
> $init
IF LSS $i $mem_size
[
ARR $tape $i 0
ADD $i $i 1
INT $i $i
JMP $init
]
MOV $i 0
MOV $j 0
MOV $MAX 256
> $interpret
IF LSS $i $len
[
ARRV $c $buf $i
IF SEQL $c +
[
ARRV $temp $tape $j
EXPR $temp ( $temp + 1 ) % $MAX
INT $temp $temp
ARR $tape $j $temp
JMP $endif2
]
IF SEQL $c -
[
ARRV $temp $tape $j
EXPR $temp ( $temp - 1 ) % $MAX
INT $temp $temp
ARR $tape $j $temp
JMP $endif2
]
IF SEQL $c $LBR
[
ARRV $temp $tape $j
IF EQL $temp 0
[
ARRV $i $pairs $i
]
JMP $endif2
]
IF SEQL $c $RBR
[
ARRV $temp $tape $j
IF NEQ $temp 0
[
ARRV $i $pairs $i
]
JMP $endif2
]
IF SEQL $c <
[
EXPR $j ( $j - 1 ) % $mem_size
JMP $endif2
]
IF SEQL $c >
[
EXPR $j ( $j + 1 ) % $mem_size
JMP $endif2
]
IF SEQL $c .
[
ARRV $temp $tape $j
CHAR $temp $temp
PRT $temp
JMP $endif2
]
IF SEQL $c ,
[
SCN $temp
ARR $tape $j $temp
]
> $endif2
ADD $i $i 1
INT $i $i
JMP $interpret
]
BYE 0
> $push
ADD $tos $tos 1
INT $tos $tos
ARR $stk $tos $i
FRET
> $pop
ARRV $temp $stk $tos
SUB $tos $tos 1
INT $tos $tos
FRET