This repository has been archived by the owner on Jul 12, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FBF.lua
executable file
·620 lines (569 loc) · 20.7 KB
/
FBF.lua
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
-- Title: FuckBrainfuck (FBF) by Tritonio
-- Author: Asimakis Konstantinos. http://inshame.blogspot.com
-- Version: 1.7.1
--
-- Converts FBF source code to Brainfuck code.
-- Reads source code from stdin and prints the resulting Brainfuck code to the stdout.
-- It also prints information messages to stderr.
--
-- Copyright (C) 2007 Asimakis Konstantinos
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License varsion 3 as
-- published by the Free Software Foundation.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
function gvn(wordy)
if vn[string.upper(wordy)]~=nil then
wordy=vn[string.upper(wordy)]
else
wordy=getvalueaftervariablecheck(wordy)
end
return wordy/1
end
function gstrictvn(wordy)
errormessage="Unknown variable: "..wordy.."."
wordy=vn[string.upper(wordy)]
return wordy/1
end
function getstrictvalue(vall)
errormessage="Wrong value: "..vall.."."
if string.sub(vall,1,1)=="'" and string.sub(vall,3,3)=="'" then vall=string.byte(string.sub(vall,2,2)) end
if string.upper(vall)=="TRUE" then vall=1 end
if string.upper(vall)=="FALSE" then vall=0 end
if math.floor(vall/1)~=vall/1 then error("kala milame gia poly megalo blaka.") end
return vall/1
end
function getvalueaftervariablecheck(vall)
errormessage="Wrong value or unknown variable: "..vall.."."
if string.sub(vall,1,1)=="'" and string.sub(vall,3,3)=="'" then vall=string.byte(string.sub(vall,2,2)) end
if string.upper(vall)=="TRUE" then vall=1 end
if string.upper(vall)=="FALSE" then vall=0 end
if math.floor(vall/1)~=vall/1 then error("kala milame gia megalo blaka.") end
return vall/1
end
function gisv(wordy)
isitval=1
if vn[string.upper(wordy)]~=nil then
isitval=0
end
return isitval
end
function tols(coma)
lss=lss+1
ls[lss]=coma
end
function fromls()
errormessage="Nothing to END."
lss=lss-1
return ls[lss+1]
end
function tocoms(coma)
for i=1,comss do
if word(coms[i],1)==word(coma,1) then errormessage="Recursion detected." error("At the moment of death I will smile; it's the triumph of shame and disease.") end
end
comss=comss+1
coms[comss]=coma
end
function fromcoms()
comss=comss-1
return coms[comss+1]
end
function set(pointer,value)
zero(pointer)
inc(pointer,value)
end
function inline(code)
for i=1,string.len(code) do
if string.sub(code,i,i)=="+" then
addplus(1)
end
if string.sub(code,i,i)=="-" then
addminus(1)
end
if string.sub(code,i,i)=="<" then
addleft(1)
end
if string.sub(code,i,i)==">" then
addright(1)
end
if string.sub(code,i,i)=="]" then
addclose(1)
end
if string.sub(code,i,i)=="[" then
addopen(1)
end
if string.sub(code,i,i)~="]" and string.sub(code,i,i)~="[" and string.sub(code,i,i)~="-" and string.sub(code,i,i)~="+" and string.sub(code,i,i)~="<" and string.sub(code,i,i)~=">" then
out=out..string.sub(code,i,i)
end
end
end
function msg(text) --0
for i=1,string.len(text) do
inc(0,string.byte(string.sub(text,i,i)))
outp(0)
dec(0,string.byte(string.sub(text,i,i)))
end
end
function comp(pointer1,isv1,pointer2,isv2,pointer3) --0,1,2,3
if isv1==0 then copy(pointer1,0) else set(0,pointer1) end
if isv2==0 then copy(pointer2,1) else set(1,pointer2) end
inc(3,1)
inc(2,1)
Suneq(3,0,1)
Sifeq(0,0,1)
inc(2,1)
set(3,0)
Eifeq(0,0,1)
Sifeq(1,0,1)
dec(2,1)
set(3,0)
Eifeq(1,0,1)
dec(0,1)
dec(1,1)
Euneq(3,0,1)
zero(0)
zero(1)
move(2,pointer3)
end
function wt(pointer,index,isv1,value,isv2) --none
if isv1==0 then copy(index,pointer+4) else inc(pointer+4,index) end --itan set
if isv2==0 then copy(value,pointer+2) else inc(pointer+2,value) end --itan set
addright(pointer)
inline("+>>>>[-[->>+<<]<<[->>+<<]>>>>]")
inline("<[-]<[->+<]")
inline("<<-[+<<-]")
addleft(pointer)
end
function rt(pointer,index,isv1,variable) --none
if isv1==0 then copy(index,pointer+4) else inc(pointer+4,index) end --itan set
addright(pointer)
inline("+>>>>[-[->>+<<]>>]")
inline("<[->+<<+>]>[-<+>]")
inline("<<<<-[+>>[-<<+>>]<<<<-]")
addleft(pointer)
move(pointer+2,variable)
end
function push(pointer,value,isv2) --none
copy(pointer+1,pointer+4)
inc(pointer+1,1)
if isv2==0 then copy(value,pointer+2) else inc(pointer+2,value) end --itan set
addright(pointer)
inline("+>>>>[-[->>+<<]<<[->>+<<]>>>>]")
inline("<[-]<[->+<]")
inline("<<-[+<<-]")
addleft(pointer)
end
function pop(pointer,variable) --none
dec(pointer+1,1)
copy(pointer+1,pointer+4)
addright(pointer)
inline("+>>>>[-[->>+<<]>>]")
inline("<[->+<<+>]>[-<+>]")
inline("<<<<-[+>>[-<<+>>]<<<<-]")
addleft(pointer)
move(pointer+2,variable)
end
function zero(pointer) --none
addright(pointer)
while string.sub(out,-1,-1)=="+" or string.sub(out,-1,-1)=="-" do out=string.sub(out,1,-2) end
if string.sub(out,-1)~="]" then out=out.."[-]" end
addleft(pointer)
end
function addminus(value) --none
while (string.sub(out,-1)=="+" and value>0) do value=value-1 out=string.sub(out,1,-2) end
for i=1,value do out=out.."-" end
end
function addright(value) --none
while (string.sub(out,-1)=="<" and value>0) do value=value-1 out=string.sub(out,1,-2) end
for i=1,value do out=out..">" end
end
function addleft(value) --none
while (string.sub(out,-1)==">" and value>0) do value=value-1 out=string.sub(out,1,-2) end
for i=1,value do out=out.."<" end
end
function addplus(value) --none
while (string.sub(out,-1)=="-" and value>0) do value=value-1 out=string.sub(out,1,-2) end
for i=1,value do out=out.."+" end
end
function addopen() --none
out=out.."["
end
function addclose() --none
if string.sub(out,-1)=="[" then out=string.sub(out,1,-2) else out=out.."]" end
end
function Suneq(pointer,pointer2,isval2) --none
if isval2==0 then
sub(pointer,0,pointer2,0,pointer)
addright(pointer)
else
addright(pointer)
addminus(pointer2)
end
addopen()
if isval2==0 then
addleft(pointer)
add(pointer,0,pointer2,0,pointer)
else
addplus(pointer2)
addleft(pointer)
end
end
function Euneq(pointer,pointer2,isval2) --none
if isval2==0 then
sub(pointer,0,pointer2,0,pointer)
addright(pointer)
else
addright(pointer)
addminus(pointer2)
end
addclose()
if isval2==0 then
addleft(pointer)
add(pointer,0,pointer2,0,pointer)
else
addplus(pointer2)
addleft(pointer)
end
end
function Sifnoteq(pointer,pointer2,isval2) --none
copy(pointer,4)
Suneq(pointer,pointer2,isval2)
end
function Eifnoteq(pointer,pointer2,isval2) --4
move(pointer,4)
if isval2==0 then
copy(pointer2,pointer)
else
inc(pointer,pointer2) --anti gia set
end
Euneq(pointer,pointer2,isval2)
move(4,pointer)
end
function Sifeq(pointer,pointer2,isval2) --5
Sifnoteq(pointer,pointer2,isval2)
inc(5,1) --anti gia set
Eifnoteq(pointer,pointer2,isval2)
Sifnoteq(5,1,1)
end
function Eifeq(pointer,pointer2,isval2) --5
Eifnoteq(5,1,1)
zero(5)
end
function inc(pointer,value) --none
addright(pointer)
addplus(value)
addleft(pointer)
end
function dec(pointer,value) --none
addright(pointer)
addminus(value)
addleft(pointer)
end
function add(pointer1,isv1,pointer2,isv2,pointer3) --0,1,2
if isv1==0 then copy(pointer1,0) else inc(0,pointer1) end --anti gia set
if isv2==0 then copy(pointer2,1) else inc(1,pointer2) end --anti gia set
Suneq(0,0,1)
inc(1,1)
dec(0,1)
Euneq(0,0,1)
move(1,pointer3)
end
function move(pointer1,pointer2) --none!
zero(pointer2)
Suneq(pointer1,0,1)
dec(pointer1,1)
inc(pointer2,1)
Euneq(pointer1,0,1)
end
function sub(pointer1,isv1,pointer2,isv2,pointer3) --0,1,2
if isv1==0 then copy(pointer1,0) else inc(0,pointer1) end --anti gia set
if isv2==0 then copy(pointer2,1) else inc(1,pointer2) end --anti gia set
Suneq(1,0,1)
dec(0,1)
dec(1,1)
Euneq(1,0,1)
move(0,pointer3)
end
function multi(pointer1,isv1,pointer2,isv2,pointer3) --0,1,2
if isv1==0 then copy(pointer1,0) else inc(0,pointer1) end --anti gia set
Suneq(0,0,1)
if isv2==0 then copy(pointer2,1) else inc(1,pointer2) end --anti gia set
Suneq(1,0,1)
dec(1,1)
inc(2,1)
Euneq(1,0,1)
dec(0,1)
Euneq(0,0,1)
move(2,pointer3)
end
function div(pointer1,isv1,pointer2,isv2,pointer3) --0,1,2
if isv1==0 then copy(pointer1,0) else inc(0,pointer1) end --anti gia set
Suneq(0,0,1)
if isv2==0 then copy(pointer2,1) else inc(1,pointer2) end --anti gia set
Suneq(1,0,1)
dec(0,1)
dec(1,1)
Sifeq(0,0,1)
Sifnoteq(1,0,1)
dec(2,1)
zero(1)
Eifnoteq(1,0,1)
Eifeq(0,0,1)
Euneq(1,0,1)
inc(2,1)
Euneq(0,0,1)
move(2,pointer3)
end
function mod(pointer1,isv1,pointer2,isv2,pointer3) --3
div(pointer1,isv1,pointer2,isv2,3)
multi(3,0,pointer2,isv2,3)
sub(pointer1,isv1,3,0,pointer3)
zero(3)
end
function a2b(pointer1,isv1,pointer2,isv2,pointer3,isv3,pointer4) --7
if isv1==0 then copy(pointer1,7) else inc(7,pointer1) end dec(7,48)
multi(7,0,10,1,7)
add(pointer2,isv2,7,0,7)
dec(7,48)
multi(7,0,10,1,7)
add(pointer3,isv3,7,0,7)
dec(7,48)
move(7,pointer4)
end
function b2a(pointer1,isv1,pointer2,pointer3,pointer4) --7
if isv1==0 then copy(pointer1,7) else inc(7,pointer1) end
mod(7,0,10,1,pointer4)
inc(pointer4,48)
div(7,0,10,1,7)
mod(7,0,10,1,pointer3)
inc(pointer3,48)
div(7,0,10,1,7)
move(7,pointer2)
inc(pointer2,48)
end
function copy(pointer1,pointer2) --6
zero(pointer2)
Suneq(pointer1,0,1)
dec(pointer1,1)
inc(pointer2,1)
inc(6,1)
Euneq(pointer1,0,1)
Suneq(6,0,1)
dec(6,1)
inc(pointer1,1)
Euneq(6,0,1)
end
function inp(pointer) --none
addright(pointer)
out=out..","
if echo then out=out.."." end
addleft(pointer)
end
function outp(pointer) --none
addright(pointer)
out=out.."."
addleft(pointer)
end
function trim(str)
return(string.gsub(str,"^%s*(.-)%s*$", "%1"))
end
function word(text,number) --none
errormessage="Wrong number of arguments."
text=text.." "
start=1 fin=string.find(text," ",start)-1
for i=2,number do
start,fin=fin+2,string.find(text," ",fin+2)-1
end
return string.sub(text,start,fin)
end
function wordcount(text) --none
curword=2
totwords=0
while pcall(word,text,curword)==true do
curword=curword+1
totwords=totwords+1
end
return totwords
end
function wordall(text,number) --none
errormessage="Wrong number of arguments."
text=text.." "
start=string.find(text," ",start)+1
return string.sub(text,start,-2)
end
function recog()
collectgarbage("collect")
local found=false
if word(string.upper(com),1)=="#ENDBLOCK" then found=true curblock=0 end
if curblock~=0 then found=true curblockcom=curblockcom+1 blocks[curblock][curblockcom]=com else
if word(string.upper(com),1)=="END" then com="E"..fromls() end
if word(string.upper(com),1)=="SET" then found=true set(gstrictvn(word(com,2)),getstrictvalue(word(com,3))) end
if word(string.upper(com),1)=="UNEQ" then found=true Suneq(gstrictvn(word(com,2)),gvn(word(com,3)),gisv(word(com,3))) tols(com) end
if word(string.upper(com),1)=="EUNEQ" then found=true Euneq(gstrictvn(word(com,2)),gvn(word(com,3)),gisv(word(com,3))) end
if word(string.upper(com),1)=="IFEQ" then found=true Sifeq(gstrictvn(word(com,2)),gvn(word(com,3)),gisv(word(com,3))) tols(com) end
if word(string.upper(com),1)=="EIFEQ" then found=true Eifeq(gstrictvn(word(com,2)),gvn(word(com,3)),gisv(word(com,3))) end
if word(string.upper(com),1)=="IFNOTEQ" then found=true Sifnoteq(gstrictvn(word(com,2)),gvn(word(com,3)),gisv(word(com,3))) tols(com) end
if word(string.upper(com),1)=="EIFNOTEQ" then found=true Eifnoteq(gstrictvn(word(com,2)),gvn(word(com,3)),gisv(word(com,3))) end
if word(string.upper(com),1)=="INC" then found=true inc(gstrictvn(word(com,2)),getstrictvalue(word(com,3))) end
if word(string.upper(com),1)=="DEC" then found=true dec(gstrictvn(word(com,2)),getstrictvalue(word(com,3))) end
if word(string.upper(com),1)=="ADD" then found=true add(gvn(word(com,2)),gisv(word(com,2)),gvn(word(com,3)),gisv(word(com,3)),gstrictvn(word(com,4))) end
if word(string.upper(com),1)=="ASCII2BYTE" then found=true a2b(gvn(word(com,2)),gisv(word(com,2)),gvn(word(com,3)),gisv(word(com,3)),gvn(word(com,4)),gisv(word(com,4)),gstrictvn(word(com,5))) end
if word(string.upper(com),1)=="BYTE2ASCII" then found=true b2a(gvn(word(com,2)),gisv(word(com,2)),gstrictvn(word(com,3)),gstrictvn(word(com,4)),gstrictvn(word(com,5))) end
if word(string.upper(com),1)=="SUB" then found=true sub(gvn(word(com,2)),gisv(word(com,2)),gvn(word(com,3)),gisv(word(com,3)),gstrictvn(word(com,4))) end
if word(string.upper(com),1)=="MULTI" then found=true multi(gvn(word(com,2)),gisv(word(com,2)),gvn(word(com,3)),gisv(word(com,3)),gstrictvn(word(com,4))) end
if word(string.upper(com),1)=="DIV" then found=true div(gvn(word(com,2)),gisv(word(com,2)),gvn(word(com,3)),gisv(word(com,3)),gstrictvn(word(com,4))) end
if word(string.upper(com),1)=="COMP" then found=true comp(gvn(word(com,2)),gisv(word(com,2)),gvn(word(com,3)),gisv(word(com,3)),gstrictvn(word(com,4))) end
if word(string.upper(com),1)=="MOD" then found=true mod(gvn(word(com,2)),gisv(word(com,2)),gvn(word(com,3)),gisv(word(com,3)),gstrictvn(word(com,4))) end
if word(string.upper(com),1)=="COPY" then found=true copy(gstrictvn(word(com,2)),gstrictvn(word(com,3))) end
if word(string.upper(com),1)=="COPYSIZE" then found=true copy(gstrictvn(word(com,2))+1,gstrictvn(word(com,3))) end
if word(string.upper(com),1)=="READ" then found=true for i=1,wordcount(com) do inp(gstrictvn(word(com,i+1))) end end
if word(string.upper(com),1)=="PRINT" then found=true for i=1,wordcount(com) do outp(gstrictvn(word(com,i+1))) end end
if word(string.upper(com),1)=="MSG" then found=true msg(wordall(com,2)) end
if word(string.upper(com),1)=="LINE" then found=true msg(linebreaker) end
if word(string.upper(com),1)=="TAB" then found=true msg(string.char(9)) end
if word(string.upper(com),1)=="BEEP" then found=true msg(string.char(7)) end
if word(string.upper(com),1)=="MSGCLEAR" then found=true msg(string.rep(string.char(8),getstrictvalue(word(com,2)))..string.rep(" ",getstrictvalue(word(com,2)))..string.rep(string.char(8),getstrictvalue(word(com,2)))) end
if word(string.upper(com),1)=="SPACE" then found=true msg(" ") end
if word(string.upper(com),1)=="#ECHO" then found=true echo=true end
if word(string.upper(com),1)=="#BYTECELLS" then found=true assume256=true end
if word(string.upper(com),1)=="#DIM" then found=true for i=1,wordcount(com) do cv=cv+1 if vn[word(string.upper(com),i+1)]~=nil then errormessage="Variable "..word(com,i+1).." has already been declared." error("Mataiotis mataiotiton ta panta mataiotis...") end variablelog=variablelog..cv.." : "..word(com,i+1).."\n" vn[word(string.upper(com),i+1)]=cv end end
if word(string.upper(com),1)=="#TABLE" then found=true cv=cv+1 variablelog=variablelog..cv.."-" vn[word(string.upper(com),2)]=cv cv=cv+getstrictvalue(word(com,3))*2+2 variablelog=variablelog..cv.." : "..word(com,2).."\n" end
if word(string.upper(com),1)=="#CUSTOM" then found=true variablelog=variablelog..cv+1 .."-" cv=cv+getstrictvalue(word(com,2)) variablelog=variablelog..cv.." : CUSTOM SPACE\n" end
if word(string.upper(com),1)=="RTABLE" then found=true rt(gstrictvn(word(com,2)),gvn(word(com,3)),gisv(word(com,3)),gstrictvn(word(com,4))) end
if word(string.upper(com),1)=="WTABLE" then found=true wt(gstrictvn(word(com,2)),gvn(word(com,3)),gisv(word(com,3)),gvn(word(com,4)),gisv(word(com,4))) end
if word(string.upper(com),1)=="POP" then found=true pop(gstrictvn(word(com,2)),gstrictvn(word(com,3))) end
if word(string.upper(com),1)=="PUSH" then found=true push(gstrictvn(word(com,2)),gvn(word(com,3)),gisv(word(com,3))) end
if word(string.upper(com),1)=="MOVETO" then found=true addright(gvn(word(com,2))) end
if word(string.upper(com),1)=="RETURNFROM" then found=true addleft(gvn(word(com,2))) end
if word(string.upper(com),1)=="BRAINFUCK" then found=true inline(wordall(com,2)) end
if word(string.upper(com),1)=="REM" then found=true end
if word(string.upper(com),1)=="--" then found=true end
if word(string.upper(com),1)=="//" then found=true end
if word(string.upper(com),1)=="#LINEBREAKS" then found=true linebreaks=getstrictvalue(word(com,2)) end
if word(string.upper(com),1)=="#LINEMODE" then found=true if string.upper(word(com,2))=="DOS" then linebreaker=string.char(13)..string.char(10) end if string.upper(word(com,2))=="LINUX" then linebreaker=string.char(10) end if string.upper(word(com,2))=="MAC" then linebreaker=string.char(13) end end
if not found and blockvars[string.upper(word(com,1))]~=nil then found=true
for i=1,blockvars[string.upper(word(com,1))][0] do
vn[blockvars[string.upper(word(com,1))][i]]=gstrictvn(string.upper(word(com,i+1)))
end
tocoms(com)
for i,subcom in ipairs(blocks[string.upper(word(com,1))]) do
com=subcom
io.stderr:write("Processing: In block "..string.upper(word(coms[comss],1))..string.char(9).." Depth: "..lss..string.char(9)..com.."\n")
if DEBUG then
recog()
else
if pcall(recog)==false then
if not errorprinted then
huston_weve_got_a_problem=true
io.stderr:write("\nERROR IN CODE LINE: "..com.."\n")
io.stderr:write(errormessage.."\n")
errorprinted=true
end
error("I used to be a break")
end
end
end
com=fromcoms()
for i=1,blockvars[string.upper(word(com,1))][0] do
vn[blockvars[string.upper(word(com,1))][i]]=nil
end
end
if word(string.upper(com),1)=="#BLOCK" then
found=true
curblock=string.upper(word(com,2))
curblockcom=0
blocks[curblock]={}
blockvars[curblock]={}
blockvars[curblock][0]=wordcount(com)-1
for i=1,wordcount(com)-1 do
blockvars[curblock][i]=string.upper(word(com,i+2))
end
end
end
if not found and com~="" then errormessage="Unknown command or instruction." error("Bas bas bas... O paraskeyas bas bas...") end
end
io.stderr:write("\nFuckBrainfuck Compiler v1.7.1 by Tritonio\n")
io.stderr:write("http://inshame.blogspot.com\n")
io.stderr:write("Copyright (C) 2007 Asimakis Konstantinos\n\n")
io.stderr:write("This program is licensed under the GNU/GPL\n")
io.stderr:write("version 3 and is distributed without any\n")
io.stderr:write("warranty. Make sure you have read the\n")
io.stderr:write("'FBF LICENSE.txt' file. You can find a copy of\n")
io.stderr:write("the license here: http://www.gnu.org/licenses/\n\n")
io.stderr:write("Reading source code from stdin.\n")
DEBUG=false
cv=7
cl=0
ls={}
lss=0
coms={}
variablelog="0-7 : Reserved\n"
comss=0
echo=false
assume256=false
vn={}
blocks={}
blockvars={}
linebreaker=string.char(10)
curblock=0
inblock=0
huston_weve_got_a_problem=false
errorprinted=false
out=""
com=io.read()
while com~=nil and huston_weve_got_a_problem==false do
cl=cl+1
com=trim(com) --tin trimarei afoy exei sigoyreytei oti den einai nil.
io.stderr:write("Processing: Line "..cl..string.char(9).." Depth: "..lss..string.char(9)..com.."\n")
if DEBUG then
recog()
else
if pcall(recog)==false then
if not errorprinted then
huston_weve_got_a_problem=true
io.stderr:write("\nERROR IN CODE LINE: "..com.."\n")
io.stderr:write(errormessage.."\n")
errorprinted=true
end
end
end
com=io.read()
end
io.stderr:write("\n")
if not huston_weve_got_a_problem then
if lss>0 or curblock~=0 then
com="" io.stderr:write("ERROR: Unclosed block or structure!\n\n")
io.stderr:write("Happy debugging...\n")
else
io.stderr:write("This program uses "..cv+1 .." cells.\n\n")
io.stderr:write("Memory map:\n"..variablelog.."\n")
while string.sub(out,-1,-1)=="+" or string.sub(out,-1,-1)=="-" or string.sub(out,-1,-1)==">" or string.sub(out,-1,-1)=="<" do
out=string.sub(out,1,-2)
end
if assume256 then
for i=256,129,-1 do
out=string.gsub(out,string.rep("%+",i),string.rep("-",256-i))
out=string.gsub(out,string.rep("%-",i),string.rep("+",256-i))
end
end
io.stderr:write("The source code has been successfully compiled!\n\nWriting "..string.len(out).." Brainfuck commands to stdout")
if linebreaks~=nil then io.stderr:write(" with line breaks every "..linebreaks.." characters") end
io.stderr:write("...\n")
if linebreaks~=nil then
for i=1,string.len(out),linebreaks do print(string.sub(out,i,i+linebreaks-1)) end
else
print(out)
end
io.stderr:write("The Brainfuck code has been written to stdout.\n")
io.stderr:write("Have fun...\n")
end
else
io.stderr:write("Happy debugging...\n")
end