Yeah, I was wondering just exactly how hard it is to implement a language that has only 8 operators involved. Not hard at all! Of course, I cheated and used graphic screens for my memory. It'll be probably a bit more complicated if I use straight memory. A bit.
The program cannot fit into one screen, but it's certainly a candidate for less than 100 lines program. It took me a couple hours because I was careless in moving the pointers.
The CYCLE subroutine is there to keep the variables within range, and the FB subroutine is there as a debugger that I use when debugging the program. So, I commented it out in the final version.
Another person, IAmAPersson (what a name!) was working on a version of the compiler as well. Check Petit Wikia for it. Maybe he posted it there by now.
I don't know the policy of this blogspot, but I know my policy and that is family friendly. I don't want to use the full name of the program. Thank you. Next time you designed a programming language, make sure you name it proper!
- REM PBF BY HARRY HARDJONO
- @INIT
- ACLS:CLEAR
- GPAGE 0:GCLS
- GPAGE 1:GCLS
- MS=30000
- PTR=0
- PC=0
- MPC=0
- CSR=0
- GPAGE1:RESTORE @HELLO
- @LOADP
- READ A$
- IF A$=="" GOTO @RUNP
- FOR I=0 TO LEN(A$)-1
- GPSET PC%256,PC/256,ASC(MID$(A$,I,1))
- PC=PC+1:NEXT
- GOTO @LOADP
- @RUNP
- PC=0:GPAGE 0
- @LOOP
- GPAGE 0:VAR=GSPOIT(PTR%256,PTR/256)
- GPAGE 1:C=GSPOIT(PC%256,PC/256)
- 'GOSUB @FB
- IF C==62 THEN PTR=PTR+1:GOSUB @CYCLE:GOTO @LOOP2
- IF C==60 THEN PTR=PTR-1:GOSUB @CYCLE:GOTO @LOOP2
- IF C==43 THEN VAR=VAR+1:GOSUB @CYCLE
- IF C==45 THEN VAR=VAR-1:GOSUB @CYCLE
- IF C==46 THEN LOCATE CSR%32,CSR/32:?CHR$(VAR);:CSR=CSR+1:GOTO @LOOP2
- IF C==44 THEN GOSUB @GETCHAR
- IF C==91 THEN MPC=1:GOSUB @SR:GOTO @LOOP2
- IF C==93 THEN MPC=1:GOSUB @SL:GOTO @LOOP2
- IF C==0 GOTO @END
- GPAGE 0:GPSET PTR%256,PTR/256,VAR
- @LOOP2
- PC=PC+1:GOSUB @CYCLE
- GOTO @LOOP
- @FB
- LOCATE 0,5:?PTR,PC,VAR
- LOCATE 0,6:?CHR$(C)
- WAIT 6
- RETURN
- @CYCLE
- IF PC<0 THEN PC=PC+49152
- IF PTR<0 THEN PTR=PTR+MS
- IF VAR<0 THEN VAR=VAR+256
- PC=PC%49152
- PTR=PTR%MS
- VAR=VAR%256
- CSR=CSR%768
- RETURN
- @GETCHAR
- A$=INKEY$():IF A$=="" GOTO @GETCHAR
- VAR=ASC(A$):WAIT 30
- RETURN
- @SR
- IF VAR!=0 THEN RETURN
- PC=PC+1:GOSUB @CYCLE
- GPAGE 1:C=GSPOIT(PC%256,PC/256)
- IF C==91 THEN MPC=MPC+1
- IF C==93 THEN MPC=MPC-1
- IF MPC<=0 THEN RETURN
- GOTO @SR
- @SL
- IF VAR==0 THEN RETURN
- PC=PC+1:GOSUB @CYCLE
- GPAGE 1:C=GSPOIT(PC%256,PC/256)
- IF C==91 THEN MPC=MPC-1
- IF C==93 THEN MPC=MPC+1
- IF MPC<=0 THEN RETURN
- GOTO @SL
- @END
- WAIT 600
- END
- @PLOP
- DATA "-[>-[.-]<]"
- DATA ">>++++[.->++++++[.-]<]"
- DATA ""
- @CAT
- DATA ",[.,]"
- DATA ""
- @HELLO
- DATA "+++++ +++++ [>+++++++"
- DATA ">+++++ +++++ >+++ >+ <<<<-]"
- DATA ">++.>+.+++++++ ..+++.>++.<<"
- DATA "+++++ +++++ +++++"
- DATA ".>.+++. ------ .----- --- .>+.>."
- DATA ""
No comments:
Post a Comment