QB64.org Forum

Active Forums => Programs => Topic started by: Larryrl on September 30, 2019, 05:27:34 pm

Title: Need help with my abcd program
Post by: Larryrl on September 30, 2019, 05:27:34 pm
OK, I have a program that I am writing. It is an interpretor called abcd. When I load  in an abcd file, it loads in a line at a time and starts on the first line and goes through each line 1 character at a  time, as each character is a command in the language I am designing.

Basically I have four commands j, J, s and S that either move up or down a line of code, or foreward or backward a position within the same line of code. So I created an abcd progrqam to print "hello" then skip down a few lines of source code and print "world" then go up to some source code lines inbetween the first group and the last group and print "again". Yet it does not move anywhere it just prints "hello" then it prints what is supposed to be again, but because of not moving anywhere like it should have, the code that prints again which is based on an intgernal accumulator does not tally up right to print the right letters. Then it prints the "world" which again does not print correctly because of the execution of the part that was supposed to print "world". I am at a loss as to how or why the movement commands I implemented did not work right.

I am attaching the source code for the abcd interpretor, as well as the source code for hello world-6.abcd which is program that is supposed to run and output correctly. Any help would be greatly appreciated.

  

Larry   
Title: Re: Need help with my abcd program
Post by: TempodiBasic on September 30, 2019, 05:54:59 pm
Sorry Larry
too much spaghetti waste my appetite!
I leave to whom has an iron stomach!

PS Welcome to the forum!
Title: Re: Need help with my abcd program
Post by: SierraKen on October 01, 2019, 03:20:42 pm
What did you compile, or make, the .abcd file with? I tried opening it with Notepad to be safe but all I get is characters and 1 sentence, no other words. I'm hesitant to run it with your .bas program because, as you say, it's a program on its own. And without me seeing the code first from a program that I never heard of or know anything about, or knowing what you made it with, I can't help you much with it. I did look at your .bas program and it looks interesting, but it's all variables without any other commands I think. I could be wrong. Also, does this have anything to do with the All Basic Code (ABC) packets from the 90's? Just wondering. I do hope you can fix your program. I just am extra careful on this computer.
Title: Re: Need help with my abcd program
Post by: Larryrl on October 01, 2019, 04:43:37 pm
The .bas program is the interpretor that is the ABCD programming language. It runs the .ABCD file. Not sure what the ABCD file does but it is supposed to print text out to the screen after several jumps from one part of the ABCD file to the other.  And no my program has nothing to do with the ABCD packets from the 90's. They were cool though. My program is a "toy"programming language meaning it really doesn't do much of anything useful. I wrote it just to see if I could. Do not be hesitant to run it in QB64. The code is harmless. It just does not jump right.

 I did however solve my problem. I used two variables to hold the current line in the source codevof the ABCD program and to hold the position in the line of code. Then after the appropriate "j, J, s and S" commands, then the interpretor gets the ":" comment which tells it to transfer control of program over to the line of code and the position we wanted to move to. It's kind of like goto in basic.
Title: Re: Need help with my abcd program
Post by: TempodiBasic on October 01, 2019, 05:47:02 pm
Hi
this is the link in your .BAS
https://esolangs.org/wiki/ABC (https://esolangs.org/wiki/ABC)

question 1 : What is an esoteric  programming language?  (Is esoteric like cryptic?)

question 2: what do you do with an esoteric programming language?

it is a training to write a real compiler?

Thanks to read

PS @ SierraKen
can you  affirm that I've been mad to run Larryl's code?
:-)  PSS you must correct the right path of .ABCD file that in the .BAS posted is on the disc F:\
Title: Re: Need help with my abcd program
Post by: SierraKen on October 01, 2019, 06:07:29 pm
Well, I decided to run it. Very interesting idea you got. When I ran it, it says, "HELLO RLRJE". I guess it decodes the .abcd file. I'm glad you got it fixed on your end. Could you paste the fixed code so we can have it as well? We do that daily in this forum. Your program is a bit beyond my knowledge though, but really cool idea. Thanks!
Title: Re: Need help with my abcd program
Post by: TempodiBasic on October 01, 2019, 06:19:31 pm
Hi SierraKen
I got the same result... but now is it wrong the code or the parser?
I think that to distinguish between these two options
or you trace the flow of program while runs the .ABCD file
or you code another .ABCD file that print all character to see if it works good.

I find Esoteric programming language in WIKI...
https://en.wikipedia.org/wiki/Esoteric_programming_language (https://en.wikipedia.org/wiki/Esoteric_programming_language)

but it is a MUST to use GOTO and Labels in an Hacking Style of programming to obscure the code!


Title: Re: Need help with my abcd program
Post by: TempodiBasic on October 01, 2019, 08:35:40 pm
Hi Larryrl

give a look to your spaghetti I must see that
to understand what don't work we have 2 way

1. tracing flow of program while it interpeter its sorgent.... it will be very useful vWatch of Fellippe!
2. try modify sorgent or write another sorgent to understand if interpreter executes well the commands!

on the 2 way I can affirm that this sorgent its ok and it is well executed
Quote
|$ee+++++++e++>*+++>*+++++++>>+++>^++++++++>*++++++++>*+++>*++++++>++++++++>
+++>*++++++>*++++++>*++++++++>+++++>$\
Yes we can agree with a space after "WORLD"... maybe "^"

so the issue lasts about new commands j J s S
going into the interpreter code it seems right also if I don't understand the different implementation of S...
but this is not the problem...

you're using a open space to program without subprograms so all your variable are global and instantly changed...
so when do you execute a J or j command you change the ln variable and just after this you jump to parse...
Code: QB64: [Select]
  1.     CASE "j"
  2.         IF ln = 1 THEN
  3.             GOTO advance
  4.         END IF
  5.         ln = ln - 1
  6.         GOTO parse
  7.  
  8.     CASE "J"
  9.         IF ln = tlns THEN
  10.             GOTO advance
  11.         END IF
  12.         IF ln = 50000 THEN
  13.             GOTO advance
  14.         END IF
  15.  
  16.         ln = ln + 1
  17.         GOTO parse
but with this line...

Code: QB64: [Select]
  1. parse:
  2.  
  3. m$ = MID$(prog$(ln), p, 1)
but
do you think to parse the second command of jumping? Or the p instruction of the before/after line of code?
so in the reality you are executing this file of sorgent
Quote
!This program prints hello and then jumps to another part of the program to print world then jumps back to print again!

|$ee+++++++e++>
*+++>
*+++++++>>
+++>^


+++>*++++++>*++++++>*++++++++>+++++>$\

                                      ++++++++>*++++++++>*+++>*++++++>++++++++>

because this line cannot work
Quote
JJJJJJsssssSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS

for the issue of global variable!...  the interpreter jumps to the white line and goes on!

I can suggest you to use more modular structure for this kind of program.
Good Luck
Title: Re: Need help with my abcd program
Post by: Larryrl on October 01, 2019, 11:31:14 pm
The j and s code was buggy but I have fixed it so it works right. The first J command moved to a new line and so none of the other J command ofr the s/S c commands could work as it had already changed lines in the code. So now the s/S u/J commands manipulate two variables and then / character I believe does the jumping based on the value of the two variables.

If you have any code you would be willing to share that shows the style of programming to which you were referring please reply and attach an example. I would love to clean up the basic code. The ABCD language itself will stay obfuscated. I find it funny that the minute I ask for help, I find the answer myself. Lol

Thanks
 
Title: Re: Need help with my abcd program
Post by: bplus on October 02, 2019, 12:15:04 am
Quote
If you have any code you would be willing to share that shows the style of programming to which you were referring please reply and attach an example.

Surely you've heard of BrainF***?

I think this came from Zeppelin, true for me also...
code$ = "++[---------->+<]>.-[++++>---<]>.-[---->+<]>++.---[----->++<]>.-------------.----.+++++++++++.[++>---<]>--.+[----->+<]>+.-------------.++++++++++++.--------.--[--->+<]>-.-[--->++<]>-.++++++++++.+[---->+<]>+++.++++++[->++<]>+.-[------>+<]>-.--[--->+<]>---.-------.-[++>---<]>+.--[->++<]>-.+[--->++<]>+"

Code: QB64: [Select]
  1. DIM memsize%, instChars$, ptr%, code$
  2. DIM i%, instruction$
  3. DIM bktCnt%, lc AS LONG
  4.  
  5. memsize% = 20000
  6. instChars$ = "+-<>.,[]" 'valid characters
  7. ptr% = 0 'memory pointer
  8. code$ = "++[---------->+<]>.-[++++>---<]>.-[---->+<]>++.---[----->++<]>.-------------.----.+++++++++++.[++>---<]>--.+[----->+<]>+.-------------.++++++++++++.--------.--[--->+<]>-.-[--->++<]>-.++++++++++.+[---->+<]>+++.++++++[->++<]>+.-[------>+<]>-.--[--->+<]>---.-------.-[++>---<]>+.--[->++<]>-.+[--->++<]>+"
  9. 'for the above "code"
  10. '_Unsigned  _byte is needed to keep values between 0 and 255, after 255 the numbers just cycle around to 0
  11. DIM memory(memsize%) AS _UNSIGNED _BYTE '<<<<<<<<<<<<  fixed by Fellippe
  12.  
  13. 'PRINT "Code translation:"
  14. r = CSRLIN
  15. c = POS(0)
  16. lc = 0
  17. FOR i% = 1 TO LEN(code$) 'loop through the code
  18.     instruction$ = MID$(code$, i%, 1) 'get the instruction we're on
  19.     LOCATE 2, 10: PRINT SPACE$(80)
  20.     LOCATE 2, 10: PRINT "mem(ptr%)"; memory(ptr%), "i%="; i%, "ptr%="; ptr%, "loop Count="; lc
  21.     LOCATE 1
  22.     SELECT CASE instruction$
  23.         CASE "+" ' +
  24.             memory(ptr%) = memory(ptr%) + 1
  25.         CASE "-" ' -
  26.             memory(ptr%) = memory(ptr%) - 1
  27.         CASE "."
  28.             LOCATE r, c
  29.             IF memory(ptr%) < 1 OR memory(ptr%) > 255 THEN
  30.                 'PRINT "?";
  31.                 PRINT "[" + LTRIM$(STR$(memory(ptr%))) + "]";
  32.             ELSE
  33.                 PRINT CHR$(memory(ptr%));
  34.             END IF
  35.             r = CSRLIN
  36.             c = POS(0)
  37.         CASE ">"
  38.             ptr% = ptr% + 1
  39.             IF ptr% > memsize% THEN
  40.                 PRINT "Memory pointer out of range"
  41.                 SLEEP
  42.                 END
  43.             END IF
  44.         CASE "<"
  45.             ptr% = ptr% - 1
  46.             IF ptr% < 0 THEN
  47.                 PRINT "Memory pointer out of range"
  48.                 SLEEP
  49.                 END
  50.             END IF
  51.         CASE "["
  52.             IF memory(ptr%) = 0 THEN
  53.                 bktCnt% = 1 'count the bracket we're on
  54.                 i% = i% + 1 'move the code pointer to the next char
  55.                 WHILE bktCnt% <> 0
  56.                     'count nested loops till we find the matching one
  57.                     IF MID$(code$, i%, 1) = "]" THEN bktCnt% = bktCnt% - 1
  58.                     IF MID$(code$, i%, 1) = "[" THEN bktCnt% = bktCnt% + 1
  59.                     i% = i% + 1 'search forward
  60.                 WEND
  61.             END IF
  62.         CASE "]"
  63.             IF memory(ptr%) <> 0 THEN
  64.                 bktCnt% = -1 'count the bracket we're on
  65.                 i% = i% - 1 'move the code pointer back a char
  66.                 WHILE bktCnt% <> 0
  67.                     'count nested loops till we find the matching one
  68.                     IF MID$(code$, i%, 1) = "]" THEN bktCnt% = bktCnt% - 1
  69.                     IF MID$(code$, i%, 1) = "[" THEN bktCnt% = bktCnt% + 1
  70.                     i% = i% - 1 'search backwards
  71.                 WEND
  72.             END IF
  73.     END SELECT
  74.     lc = lc + 1
  75.     _LIMIT 100
  76.  
  77.  
Title: Re: Need help with my abcd program
Post by: SMcNeill on October 02, 2019, 12:40:49 am
Downloaded your abcd.bas, and like TempodiBasic, I found all those GOTOs to be rather daunting to deal with.  Once I quit quivering from my mind's initial instinct to hide from all the jumping around which it seemed the code was doing, I discovered that things weren't half as complicated, or bad to sort out, as I'd first assumed.

Always being one who likes to help teach others, I decided to take a little bit and clean up the code for you somewhat.  See if this looks a little better for you (and Tempodi) to work with and interact with:

Code: QB64: [Select]
  1. ' ABCD interpretor
  2. ' Coded by Larry R. Lowe in QB64 for windows 10
  3.  
  4. ' Original ABC Esoteric Programming language created by orange, a user from the esolang wiki at https://esolangs.org/wiki/ABC
  5. ' This interpretor is the original ABC programming language with different 1 single character commands, and a few extra ones thrown in
  6. ' This version has among other things a second independant accumulator, and choice blocks.
  7.  
  8. ' ! - Toggle remark mode on or off. When on everything between the first ! and the second ! is a comment
  9. ' # - runs the file specified between the % signs
  10. ' $ - Toggle ASCII output mode.  When on, the c instruction prints the first accumulator as an ASCII character, if it is >0 and <256.
  11. ' % - toggle the next filename to run block on or off
  12. ' & - Toggle the direction of the multiplication or division of the first accumulator.
  13. ' * - Toggle direction of first accumulator. When on, a + command decreases the first accumulatorm and when off a + command increases the first accumulator
  14. ' ; - Debug.  Prints out first accumulator as a number and ascii character.
  15. ' ? - Set first accumulator to a random number between 0 and first accumulator
  16. ' ^ - prints a space
  17. ' | - clear the screen
  18. ' + - Increase or decrease the value of the first accumulator
  19. ' < - Invert first accumulator
  20. ' > - Output the first accumulator
  21. ' 0 - Begin/ end choice0 block containing a file name to begin interpreting if 0 is pressed
  22. ' 1 - Begin/ end choice1 block containing a file name to begin interpreting if 1 is pressed
  23. ' 2 - Begin/ end choice2 block containing a file name to begin interpreting if 2 is pressed
  24. ' 3 - Begin/ end choice3 block containing a file name to begin interpreting if 3 is pressed
  25. ' 4 - Begin/ end choice4 block containing a file name to begin interpreting if 4 is pressed
  26. ' 5 - Begin/ end choice5 block containing a file name to begin interpreting if 5 is pressed
  27. ' 6 - Begin/ end choice6 block containing a file name to begin interpreting if 6 is pressed
  28. ' 7 - Begin/ end choice7 block containing a file name to begin interpreting if 7 is pressed
  29. ' 8 - Begin/ end choice8 block containing a file name to begin interpreting if 8 is pressed
  30. ' 9 - Begin/ end choice9 block containing a file name to begin interpreting if 9 is pressed
  31. ' a - Increase or decrease the value of the second accumulator
  32. ' b - Increrment the background color number by 1
  33. ' c - decrerment the background color number by 1
  34. ' d - multiply the second accumulator by 1, 5 or 10
  35. ' e - toggle the amount to increase or decrease the first accumulator by 1, 5 orf 10
  36. ' f - Increrment the foreground color number by 1
  37. ' g - decrerment the foreground color number by 1
  38. ' h - Toggle ASCII output mode.  When on, the c instruction prints the second accumulator as an ASCII character, if it is >0 and <256.
  39. ' i - Set second accumulator to a random number between 0 and second accumulator
  40. ' k - resets the foreground color to 0
  41. ' l - Loop back to the beginning of the program.  first accumulator and ASCII mode does not reset.
  42. ' m - resets the background color to 0
  43. ' n - prints a newline
  44. ' o - changes the foreground and background to the colors specified by the k, m, f, g, b and c commands
  45. ' p - Toggle direction of second accumulator. When on, an a command decreases the second accumulatorm and when off an a command increases the second accumulator
  46. ' r - Set first accumulator to 0
  47. ' t - Output the second accumulator
  48. ' u - Invert second accumulator
  49. ' v - Toggle the direction of the multiplication or division of the second accumulator. When off the x command multiplies the first accumulator by 1, 5 or 10, when on it divides it by 1, 5 or 10
  50. ' w - toggle the amount to increase or decrease the second accumulator by 1, 5 orf 10
  51. ' x - multiply the first accumulator by 1, 5 or 10
  52. ' z - Set second accumulator to 0
  53. ' H - Print Hello World
  54. ' ) - starts a cat block for use in writing a cat pgogram
  55. ' K - waits until ther user presses 0 througgh 9. It works with the above listed choice blocks. At least 1 choice block must be in the source code to use the K command.
  56. ' j - move the source code pointer up 1 line
  57. ' J - move the source code pointer down 1 line
  58. ' s - move the source code pointer left 1 character
  59. ' S - move the source code pointer right 1 character
  60.  
  61.  
  62. begin:
  63.  
  64.  
  65. ' Here we mak it full screen. If it looks like it is going to be unstable, or if it screws up, just remove these 2 lines
  66. '_FULLSCREEN
  67.  
  68.  
  69. DIM prog$(50000), a$(50000)
  70.  
  71. row = 1: col = 1
  72. fc = 7 ' foreground color variable
  73. bc = 0 ' bsackground color variable
  74. x = 0 ' index for an array to load in the prgoram 1 line at a time
  75. ln = 1 ' starting line of code to begin interpreting
  76. acc = 0 ' first accumulator variable
  77. acc2 = 0 ' second accumulator variable
  78. aom = 0 ' variable to hold first accumulator output mode
  79. aom2 = 0 ' variable to hold second accumulator output mode
  80. p = 1 ' variable to hold the number representing which character in the line we are interpreting
  81. plus = 1 ' variable to hold the amount added to or subtracted from the first accumulator
  82. plus2 = 1 ' variable to hold the amount added to or subtracted from the second accumulator
  83.  
  84. ad = 0 ' sets the first accumulator direction mode 0 =add 1 = subtract
  85. ad2 = 0 ' sets the second accumulator direction mode 0 =add 1 = subtract
  86. mul = 0
  87. mul2 = 0
  88. fm = 0
  89. lem = 0
  90. lem2 = 0
  91. c0 = 0
  92. c1 = 0
  93. c2 = 0
  94. c3 = 0
  95. c4 = 0
  96. c5 = 0
  97. c6 = 0
  98. c7 = 0
  99. c8 = 0
  100. c9 = 0
  101. cat = 0
  102.  
  103. ptjt = 0
  104. ltjt = 0
  105.  
  106. cm = 0 ' variable to hold the comment mode 0 = not the beginning of a comment 1 = beginning of comment
  107. 'The "!" toggles this cm variable
  108.  
  109. COLOR fc, bc: CLS
  110.  
  111. ' This routine is where we get the command line to determine if the user gave the interpretor a file name to work with.
  112.  
  113. filename$ = COMMAND$
  114.  
  115. filename$ = "hello world-6.abcd"
  116.  
  117. load:
  118.  
  119. ' here we load a systems file coded in ABCD itself, to tell the user that a file name is required on the command line.
  120. ' it is for that reason, you can't just click on the ABCD icon and expect to get results.
  121.  
  122. IF filename$ = "" THEN LOCATE 24, 1: PRINT "Usage abcd filename.abcd": END
  123.  
  124. ' We will open the file in sequential access mode and read it in one line at a time
  125.  
  126. OPEN filename$ FOR INPUT AS #1
  127.     x = x + 1
  128.     LINE INPUT #1, prog$(x)
  129.  
  130. tlns = x
  131. x = 1
  132.  
  133. ' now that we have the source code read into the computer's memory,
  134. ' we start at line 1 and we go from the beginning of it to the end of it
  135. ' one character at a time because all commands are single characters in length.
  136. ' We now parse each character so it does not matter if our source code is all
  137. ' on one line, or if it is broken up into many lines.
  138.  
  139.     parse:
  140.  
  141.     m$ = MID$(prog$(ln), p, 1)
  142.  
  143.  
  144.     ' Here we do what is necessary if we find a block.
  145.     ' The !, @, 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9 characters
  146.     ' are block commands. A block must contain one of these
  147.     ' commands followed by the required information, and then
  148.     ' end with the same command. A comment block starts and
  149.     ' ends with the ! character. Everything between the two
  150.     ' exclamation points is ignored by the interpretor as it
  151.     ' is a comment.
  152.  
  153.     IF cm = 1 AND m$ <> "!" THEN GOTO advance
  154.     IF cm = 1 AND m$ = "!" THEN cm = 0: GOTO advance
  155.  
  156.     IF fm = 0 AND m$ = "%" THEN fm = 1: GOTO advance
  157.     IF fm = 1 AND m$ <> "%" THEN nfn$ = nfn$ + m$: GOTO advance
  158.     IF fm = 1 AND m$ = "%" THEN fm = 0: GOTO advance
  159.  
  160.  
  161.     IF c0 = 0 AND m$ = "0" THEN c1 = 1: GOTO advance
  162.     IF c0 = 1 AND m$ <> "0" THEN choice0$ = choice0$ + m$: GOTO advance
  163.     IF c0 = 1 AND m$ = "0" THEN c0 = 0: GOTO advance
  164.  
  165.     IF c1 = 0 AND m$ = "1" THEN c1 = 1: GOTO advance
  166.     IF c1 = 1 AND m$ <> "1" THEN choice1$ = choice1$ + m$: GOTO advance
  167.     IF c1 = 1 AND m$ = "1" THEN c0 = 0: GOTO advance
  168.  
  169.     IF c2 = 0 AND m$ = "2" THEN c2 = 1: GOTO advance
  170.     IF c2 = 1 AND m$ <> "2" THEN choice2$ = choice2$ + m$: GOTO advance
  171.     IF c2 = 1 AND m$ = "2" THEN c2 = 0: GOTO advance
  172.  
  173.     IF c3 = 0 AND m$ = "3" THEN c3 = 1: GOTO advance
  174.     IF c3 = 1 AND m$ <> "3" THEN choice3$ = choice3$ + m$: GOTO advance
  175.     IF c3 = 1 AND m$ = "3" THEN c3 = 0: GOTO advance
  176.  
  177.     IF c4 = 0 AND m$ = "4" THEN c4 = 1: GOTO advance
  178.     IF c4 = 1 AND m$ <> "4" THEN choice4$ = choice4$ + m$: GOTO advance
  179.     IF c4 = 1 AND m$ = "4" THEN c4 = 0: GOTO advance
  180.  
  181.     IF c5 = 0 AND m$ = "5" THEN c5 = 1: GOTO advance
  182.     IF c5 = 1 AND m$ <> "5" THEN choice5$ = choice5$ + m$: GOTO advance
  183.     IF c5 = 1 AND m$ = "5" THEN c5 = 0: GOTO advance
  184.  
  185.     IF c6 = 0 AND m$ = "6" THEN c6 = 1: GOTO advance
  186.     IF c6 = 1 AND m$ <> "6" THEN choice6$ = choice6$ + m$: GOTO advance
  187.     IF c6 = 1 AND m$ = "6" THEN c6 = 0: GOTO advance
  188.  
  189.     IF c7 = 0 AND m$ = "7" THEN c7 = 1: GOTO advance
  190.     IF c7 = 1 AND m$ <> "7" THEN choice7$ = choice7$ + m$: GOTO advance
  191.     IF c7 = 1 AND m$ = "7" THEN c7 = 0: GOTO advance
  192.  
  193.     IF c8 = 0 AND m$ = "8" THEN c8 = 1: GOTO advance
  194.     IF c8 = 1 AND m$ <> "8" THEN choice8$ = choice8$ + m$: GOTO advance
  195.     IF c8 = 1 AND m$ = "8" THEN c8 = 0: GOTO advance
  196.  
  197.     IF c9 = 0 AND m$ = "9" THEN c9 = 1: GOTO advance
  198.     IF c9 = 1 AND m$ <> "9" THEN choice9$ = choice9$ + m$: GOTO advance
  199.     IF c9 = 1 AND m$ = "9" THEN c9 = 0: GOTO advance
  200.  
  201.     IF cat = 0 AND m$ = ")" THEN cat = 1: cat$ = cat$ + m$: GOTO advance
  202.     IF cat = 1 AND m$ <> ")" THEN cat$ = cat$ + m$: GOTO advance
  203.     IF cat = 1 AND m$ = ")" THEN c9 = 0: cat$ = cat$ + m$: PRINT cat$;: GOTO advance
  204.  
  205.  
  206.  
  207.     SELECT CASE m$
  208.  
  209.  
  210.         CASE "$": aom = aom XOR 1
  211.         CASE "(": lem = lem XOR 1
  212.         CASE "h": aom2 = aom2 XOR 1
  213.         CASE "*": ad = ad XOR 1
  214.         CASE "&": mul = mul XOR 1
  215.         CASE "v": mul2 = mul2 XOR 1
  216.         CASE "p": ad2 = ad2 XOR 1
  217.         CASE ";": PRINT STR$(acc); " "; CHR$(acc)
  218.         CASE "+"
  219.             IF ad = 0 THEN
  220.                 acc = acc + plus
  221.             ELSEIF ad = 1 THEN
  222.                 acc = acc - plus
  223.             END IF
  224.         CASE "x"
  225.             IF mul = 0 THEN
  226.                 acc = acc * plus
  227.             ELSEIF mul = 1 THEN
  228.                 acc = acc / plus
  229.             END IF
  230.         CASE "a"
  231.             IF ad2 = 0 THEN
  232.                 acc2 = acc2 + plus
  233.             ELSEIF ad2 = 1 THEN
  234.                 acc2 = acc2 - plus
  235.                 GOTO advance
  236.             END IF
  237.         CASE "d"
  238.             IF mul2 = 0 THEN
  239.                 acc2 = acc2 * plus2
  240.             ELSEIF mul2 = 1 THEN
  241.                 acc2 = acc2 / plus2
  242.             END IF
  243.         CASE ">", "u" 'u was EXACTLY the same code as >.   Was this intentional??
  244.             IF aom = 0 THEN PRINT LTRIM$(STR$(acc));
  245.             IF aom = 1 THEN
  246.                 IF acc = 0 OR acc > 255 THEN
  247.                     PRINT LTRIM$(STR$(acc));
  248.                 ELSE
  249.                     PRINT CHR$(acc);
  250.                 END IF
  251.             END IF
  252.         CASE "t", "<" '< was EXACTLY the same case as t.  Once again, is this intentional, or just not implemented code yet?
  253.             IF LEN(STR$(acc)) <> 1 THEN
  254.                 acc$ = STR$(acc): accl = LEN(acc$)
  255.                 FOR i = accl TO 1 STEP -1
  256.                     tmp$ = tmp$ + MID$(acc$, i, 1)
  257.                 NEXT i
  258.                 acc = VAL(tmp$)
  259.             END IF
  260.             'CASE "u"' Removed completely as it's duplicate code.  Handled above with ">"
  261.             'CASE "<"' Removed the same as u above.  It's duplicate code and handled with "t"
  262.         CASE "e"
  263.             IF plus = 1 THEN
  264.                 plus = 5
  265.             ELSEIF plus = 5 THEN
  266.                 plus = 10
  267.             ELSEIF plus = 10 THEN
  268.                 plus = 1
  269.             END IF
  270.         CASE "w"
  271.             IF plus2 = 1 THEN
  272.                 plus2 = 5: 'GOTO advance
  273.             ELSEIF plus2 = 5 THEN
  274.                 plus2 = 10: 'GOTO advance
  275.             ELSEIF plus2 = 10 THEN
  276.                 plus2 = 1: 'GOTO advance
  277.             END IF
  278.         CASE "f": fc = fc + 1
  279.         CASE "g": fc = fc - 1
  280.         CASE "b": bc = bc + 1
  281.         CASE "c": bc = bc - 1
  282.         CASE "|": CLS
  283.         CASE "k": fc = 0
  284.         CASE "m": bc = 0
  285.         CASE "l": ln = 1
  286.         CASE "r": acc = 0
  287.         CASE "z": acc2 = 0
  288.         CASE "o"
  289.             IF fc > 0 AND bc > 0 THEN COLOR fc, bc
  290.             IF fc = 0 AND bc <> 0 THEN COLOR 7, bc
  291.         CASE "?"
  292.             getnum:
  293.             RANDOMIZE TIMER
  294.  
  295.             ntg = INT(RND * acc)
  296.             IF ntg > acc THEN GOTO getnum
  297.  
  298.             IF lem = 1 AND ntg < 10 THEN GOTO getnum
  299.             acc = ntg
  300.         CASE "i"
  301.             getnum2:
  302.             RANDOMIZE TIMER
  303.  
  304.             ntg2 = INT(RND * acc2)
  305.             IF ntg2 > acc2 THEN GOTO getnum2
  306.             IF lem2 = 1 AND ntg2 < 10 THEN GOTO getnum2
  307.             acc2 = ntg2
  308.         CASE "n": PRINT " "
  309.         CASE "~"
  310.             getnum3:
  311.             RANDOMIZE TIMER
  312.  
  313.             ntg = INT(RND * 9)
  314.             IF ntg < 0 THEN GOTO getnum3
  315.             IF ntg > 9 THEN GOTO getnum3
  316.             acc = ntg
  317.             '        GOTO advance
  318.         CASE "^": PRINT " ";
  319.         CASE "!": cm = cm XOR 1
  320.         CASE "%": fm = fm XOR 1
  321.         CASE "": 'GOTO advance
  322.         CASE "0": c0 = c0 XOR 1
  323.         CASE "1": c1 = c1 XOR 1
  324.         CASE "2": c2 = c2 XOR 1
  325.         CASE "3": c3 = c3 XOR 1
  326.         CASE "4": c4 = c4 XOR 1
  327.         CASE "5": c5 = c5 XOR 1
  328.         CASE "6": c6 = c6 XOR 1
  329.         CASE "7": c7 = c7 XOR 1
  330.         CASE "8": c8 = c8 XOR 1
  331.         CASE "9": c9 = c9 XOR 1
  332.         CASE ")": cat = cat XOR 1
  333.  
  334.             ' This is the routine where we wait for the user to press only the keys 0-9, nad thehn we load a new source code based on what they chose.
  335.             ' There must be at least one choice block in your code, otherwise the interpretor does not have any source code file to interpret at that
  336.             ' point and will crash.
  337.  
  338.         CASE "K"
  339.             DO
  340.                 z$ = INKEY$
  341.                 _LIMIT 30 'play nice with your CPU and other apps while waiting on the user to press their key
  342.             LOOP UNTIL z$ >= "0" AND z$ <= "9"
  343.             IF z$ = "0" THEN filename$ = choice0$
  344.             IF z$ = "1" THEN filename$ = choice1$
  345.             IF z$ = "2" THEN filename$ = choice2$
  346.             IF z$ = "3" THEN filename$ = choice3$
  347.             IF z$ = "4" THEN filename$ = choice4$
  348.             IF z$ = "5" THEN filename$ = choice5$
  349.             IF z$ = "6" THEN filename$ = choice6$
  350.             IF z$ = "7" THEN filename$ = choice7$
  351.             IF z$ = "8" THEN filename$ = choice8$
  352.             IF z$ = "9" THEN filename$ = choice9$
  353.             GOTO load
  354.         CASE "H": PRINT "hello world";
  355.         CASE "B": ltjt = 0
  356.         CASE "j"
  357.             IF ln <> 1 THEN
  358.                 ln = ln - 1
  359.                 GOTO parse
  360.             END IF
  361.         CASE "J"
  362.             IF ln <> tlns AND ln <> 50000 THEN
  363.                 ln = ln + 1
  364.                 GOTO parse
  365.             END IF
  366.         CASE "s"
  367.             IF p <> 1 THEN
  368.                 p = p - 1
  369.                 GOTO parse
  370.             END IF
  371.  
  372.         CASE "S"
  373.             'All conditions GOTO advance, which we fall through the SELECT CASE to automatically.
  374.             'Everything is commented out just to show it's not needed.
  375.  
  376.             'IF p = LEN(prog$(ln)) THEN
  377.             '    GOTO advance
  378.             'END IF
  379.  
  380.             'GOTO advance
  381.  
  382.  
  383.         CASE "\": END
  384.  
  385.         CASE ELSE ' This routine ignores everytthing else that is not a command and just moves on.
  386.     END SELECT
  387.  
  388.     ' The routines advance is where we move to the next character in the string that is the current line of code
  389.     ' When we reach the end of the line, the advance2 routine moves to the next line and reset the position to the
  390.     ' first character and start from there.
  391.  
  392.     advance:
  393.  
  394.     p = p + 1
  395.     IF p >= LEN(prog$(ln)) + 1 THEN
  396.  
  397.         ln = ln + 1: p = 1
  398.         IF ln = tlns + 1 AND nfn$ = "" THEN
  399.             END
  400.         END IF
  401.  
  402.         IF ln = 50001 AND nfn$ = "" THEN END
  403.  
  404.         IF ln = tlns + 1 AND nfn$ <> "" THEN
  405.             filename$ = nfn$: nfn$ = "": x = 0: p = 1: ln = 1: GOTO load
  406.         END IF
  407.  
  408.         IF ln = 50001 AND nfn$ <> "" THEN
  409.             filename$ = nfn$: nfn$ = "": x = 0: p = 1: ln = 1: GOTO load
  410.         END IF
  411.     END IF
  412.  
  413. LOOP 'remove this goto and let the DO... LOOP handle the process without need for GOTO

From 725 lines down to 417, and the majority of those "lost lines" were one of two things:

1) I simply removed a ton of GOTO advance statements which were inside the SELECT CASE structure.  There's no reason to GOTO advance, as the advance label falls immediately after the SELECT CASE.  Simply let the flow fall through like normal.

2) This long, repeating sequence of code can be simplifed down to a single line:

Code: [Select]
        IF cm = 0 THEN
            cm = 1
            GOTO advance
        END IF

        IF cm = 1 THEN
            cm = 0
            GOTO advance
        END IF

Since we can ignore the GOTO advance (we flow directly down to it automatically), all you need here is:

Code: [Select]
cm = cm XOR 1
XOR is our "Exclusive OR" command, and when used in such a manner it works as basically a toggle to swap between values of 1 and 0.



A few other changes were made, but those were just some minor logic.

I did find a few areas of duplicate processing ("t" and "<" are the same, as are ">" and "u"), and I wasn't certain if you realized you could set more than one condition for a SELECT CASE or not, so I did so for you, as an example.

I didn't bother to clean up any of the IF c0 = 0 AND m$ = "0"... lines, but I couldn't help but wonder: Wouldn't those be best served by making an array to handle them?  Instead of c0, c1, c2...c9, why not DIM c(0 TO 9) and then use the array and put all that stuff into a FOR..NEXT loop?



Use it, or not, I don't mind.  I just thought I'd share, to help show a way you can restructure and clean up the code so it wouldn't be so daunting for others, if they ever have to help you with it again in the future. 
Title: Re: Need help with my abcd program
Post by: Larryrl on October 02, 2019, 01:47:50 am
I like it over all, but I added back the advance2 because going to it, was needed in one or two places. Also, those case commands you thought were duplicated


            'CASE "u"' Removed completely as it's duplicate code.  Handled above with ">"
            'CASE "<"' Removed the same as u above.  It's duplicate code and handled with "t"
 
were not duplicates and you are right they do exactly the same thing but to a different variable named acc2 as this language has 2 accumulators instead of 1 like the original abc specs called for.

Originally this was to be a duplicate of someone else's language from the eso wiki 1 because the one supplied as code to be coppied and pasted was in java and I do not do java. I dabble in c# but that's as new as I get. And 2, because all other links were dead. However, after duplicating it in QB64 right down to the last detail I though hey this could be better and do more. That is when I added the 2nd accumulator and re added my own single charqacter commands. Then I began adding more to the code, so I renamed it abcd. The original never jumped through the code, that was all my idea, and why I needed help. 

Thanks for the xor code I always wondered what the xor really did and I can see how nice it makes it over how I had it. I am 55 and have been programming for 39 years, and it still amazes me when I find new and usefull ways to code programs. I merged the code for the jumps from my .bas file with the cleaned  up code from your version, and It does the same thing it did before, only far more efficiently, and certainly looks a whole lot better.

Thanks again for all of your help.

Larry
Title: Re: Need help with my abcd program
Post by: TempodiBasic on October 02, 2019, 09:22:52 am
Hi Larryln
fine to read that you have solved alone your problem of spaghetti code!
Quote
The j and s code was buggy but I have fixed it so it works right.
Quote
I find it funny that the minute I ask for help, I find the answer myself. Lol

but  can you share to let see us the working version?
Title: Re: Need help with my abcd program
Post by: Larryrl on October 02, 2019, 11:16:24 am
Here is the code in an attahment, and some sample programs to interpret. It is part my code and part from SMcNeill, whom as you know cleaned up my code.   [ This attachment cannot be displayed inline in 'Print Page' view ]    [ This attachment cannot be displayed inline in 'Print Page' view ]  

When I posted it originally, it didn't jump correctly. Therefore his cleaned up version did not jump right either. So, I had to add the part from my code that I had fixed of the jumping code to his so that it would work, but at the me time be better loking code. The problem was I needed to go from one place to another in the code of my sample programs. The j, J, s and S commands were suppposed to do that, but after the first J command it could not work right because it wasn't on the same line where the jump commands were there in a single row. So I had to set a couple of variables to the current position and line in the code of my interpreted sample program then modify those each time there was a j, J, s or S command. Then when the variables reached the right position and line to where the interpretor should start working next, I had to have an actual command to move to that position in the code.
Title: Re: Need help with my abcd program
Post by: TempodiBasic on October 02, 2019, 04:01:27 pm
Thanks for sharing Larryrl

but running this your second code ABCD.bas that I have saved on the disk as ABCD2.bas (to not overwrite the first one) it seems stopped at the issue
see screenshots
  [ This attachment cannot be displayed inline in 'Print Page' view ]  
  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Need help with my abcd program
Post by: Petr on October 03, 2019, 08:03:43 am
Hi TempodiBasic.

You are right. I analyzed the abcd file according to the policy described in the program, and concluded that the program with which the abcd file was created is faulty or the policy described in the program is invalid:

Filename: hello world-6.abcd

Code: [Select]

In start are values increased, star swap it to decrease and back


|$ee+++++++e++>                                          one "e" = * 1, two "ee" = * 10:  10 * 7(seven plus) + 1* 2 = 72. CHR$(72) = "H"
*+++>                                                   * star = decrease, so next character is CHR$(72) - 3 = 69 = "E"
*+++++++>>                                              * star = increase, so next character is 69 + 7 = 76 = "L", because is here ">>" so output is "LL"
+++>^JJJJJJsssssSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS/  next character is 76 + 3 = 79 = "O"



+++>*++++++>*++++++>*++++++++>+++++>$\                  next character is 79 + 3 = "R", 79 - 6 = 73 = "L", 73 + 6 = 79 = "R", 79 - 8 = 71 = "J", 71 - 5 = 66 = "E"

+++++++++>*++++++++>*+++>*++++++>++++++++>^  '66 - 9 = 55,  55 + 8 = 63, 63 - 3 = 60, 60 + 6 = 66, 66 + 8 = 74
                                                   (7),          (?),         (<),        (B),         (J)
jjjssssssssssssssssssssssssssssssssssssss/
Title: Re: Need help with my abcd program
Post by: Larryrl on October 03, 2019, 12:30:04 pm
Hi TempodiBasic

Here is a new version of the interpretor and the hello world-1.abcd and the hello world-2.abcd. Both abcd's are needed to run. The first runs the 2nd one. Also, make sure to study the top of th source code as some commands have been changed. I decided to make a couple of the toggles into 2 seperate characters as it was too confusing even for me.    

Larry
Title: Re: Need help with my abcd program
Post by: Petr on October 03, 2019, 12:38:12 pm
Hello World  abcd file for your previous version :)

Title: Re: Need help with my abcd program
Post by: Larryrl on October 03, 2019, 01:58:47 pm
I am also adding hello world-1 here as for Petr. You can use it with the newer version of the abcd.exe. Also for TempodiBasic the new version of hello world-4 which is the one with the jumps that actually works right and does not mis print the ascii code as it did before.
  [ This attachment cannot be displayed inline in 'Print Page' view ]    [ This attachment cannot be displayed inline in 'Print Page' view ]  

Happy Coding

Larry
Title: Re: Need help with my abcd program
Post by: TempodiBasic on October 03, 2019, 05:18:16 pm
Hi Larryrl

in this evening I have spent some time to make a mod of your interpreter...
I have used my manner to program so you find a FUNCTION that counts the metacomands of moving the cursor of the interpreter

give a try to this mod version in which the original jJsS work well...

PS I REMark again... in the Hello World6.abcd  you must correct the output adding a space after World! So it is fine.
Code: QB64: [Select]
  1. ' ABCD interpr etor
  2. ' Coded by Larry R. Lowe in QB64 for windows 10
  3.  
  4. ' Original ABC Esoteric Programming language created by orange, a user from the esolang wiki at https://esolangs.org/wiki/ABC
  5. ' This interpretor is the original ABC programming language with different 1 single character commands, and a few extra ones thrown in
  6. ' This version has among other things a second independant accumulator, and choice blocks.
  7.  
  8. ' ! - Toggle remark mode on or off. When on everything between the first ! and the second ! is a comment
  9. ' # - runs the file specified between the % signs
  10. ' $ - Toggle ASCII output mode.  When on, the c instruction prints the first accumulator as an ASCII character, if it is >0 and <256.
  11. ' % - toggle the next filename to run block on or off
  12. ' & - Toggle the direction of the multiplication or division of the first accumulator.
  13. ' * - Toggle direction of first accumulator. When on, a + command decreases the first accumulatorm and when off a + command increases the first accumulator
  14. ' ; - Debug.  Prints out first accumulator as a number and ascii character.
  15. ' ? - Set first accumulator to a random number between 0 and first accumulator
  16. ' ^ - prints a space
  17. ' | - clear the screen
  18. ' + - Increase or decrease the value of the first accumulator
  19. ' < - Invert first accumulator
  20. ' > - Output the first accumulator
  21. ' 0 - Begin/ end choice0 block containing a file name to begin interpreting if 0 is pressed
  22. ' 1 - Begin/ end choice1 block containing a file name to begin interpreting if 1 is pressed
  23. ' 2 - Begin/ end choice2 block containing a file name to begin interpreting if 2 is pressed
  24. ' 3 - Begin/ end choice3 block containing a file name to begin interpreting if 3 is pressed
  25. ' 4 - Begin/ end choice4 block containing a file name to begin interpreting if 4 is pressed
  26. ' 5 - Begin/ end choice5 block containing a file name to begin interpreting if 5 is pressed
  27. ' 6 - Begin/ end choice6 block containing a file name to begin interpreting if 6 is pressed
  28. ' 7 - Begin/ end choice7 block containing a file name to begin interpreting if 7 is pressed
  29. ' 8 - Begin/ end choice8 block containing a file name to begin interpreting if 8 is pressed
  30. ' 9 - Begin/ end choice9 block containing a file name to begin interpreting if 9 is pressed
  31. ' a - Increase or decrease the value of the second accumulator
  32. ' b - Increrment the background color number by 1
  33. ' c - decrerment the background color number by 1
  34. ' d - multiply the second accumulator by 1, 5 or 10
  35. ' e - toggle the amount to increase or decrease the first accumulator by 1, 5 orf 10
  36. ' f - Increrment the foreground color number by 1
  37. ' g - decrerment the foreground color number by 1
  38. ' h - Toggle ASCII output mode.  When on, the c instruction prints the second accumulator as an ASCII character, if it is >0 and <256.
  39. ' i - Set second accumulator to a random number between 0 and second accumulator
  40. ' k - resets the foreground color to 0
  41. ' l - Loop back to the beginning of the program.  first accumulator and ASCII mode does not reset.
  42. ' m - resets the background color to 0
  43. ' n - prints a newline
  44. ' o - changes the foreground and background to the colors specified by the k, m, f, g, b and c commands
  45. ' p - Toggle direction of second accumulator. When on, an a command decreases the second accumulatorm and when off an a command increases the second accumulator
  46. ' r - Set first accumulator to 0
  47. ' t - Output the second accumulator
  48. ' u - Invert second accumulator
  49. ' v - Toggle the direction of the multiplication or division of the second accumulator. When off the x command multiplies the first accumulator by 1, 5 or 10, when on it divides it by 1, 5 or 10
  50. ' w - toggle the amount to increase or decrease the second accumulator by 1, 5 orf 10
  51. ' x - multiply the first accumulator by 1, 5 or 10
  52. ' z - Set second accumulator to 0
  53. ' H - Print Hello World
  54. ' ) - starts a cat block for use in writing a cat pgogram
  55. ' K - waits until ther user presses 0 througgh 9. It works with the above listed choice blocks. At least 1 choice block must be in the source code to use the K command.
  56. ' j - move the source code pointer up 1 line
  57. ' J - move the source code pointer down 1 line
  58. ' s - move the source code pointer left 1 character
  59. ' S - move the source code pointer right 1 character
  60. ' A -
  61. ' B -
  62. ' C -
  63. ' D -
  64. ' E -
  65. ' F -
  66. ' G -
  67. ' H -
  68. ' I -
  69. ' L -
  70. ' M -
  71. ' B -
  72. ' O -
  73. ' P -
  74. ' Q -
  75. ' q -
  76. ' R -
  77. ' T -
  78. ' U -
  79. ' V -
  80. ' W -
  81. ' X -
  82. ' Y -
  83.  
  84.  
  85. begin:
  86.  
  87.  
  88. ' Here we mak it full screen. If it looks like it is going to be unstable, or if it screws up, just remove these 2 lines
  89. '_FULLSCREEN
  90.  
  91.  
  92. DIM prog$(50000), a$(50000)
  93.  
  94. row = 1: col = 1
  95. fc = 7 ' foreground color variable
  96. bc = 0 ' bsackground color variable
  97. x = 0 ' index for an array to load in the prgoram 1 line at a time
  98. ln = 1 ' starting line of code to begin interpreting
  99. acc = 0 ' first accumulator variable
  100. acc2 = 0 ' second accumulator variable
  101. aom = 0 ' variable to hold first accumulator output mode
  102. aom2 = 0 ' variable to hold second accumulator output mode
  103. p = 1 ' variable to hold the number representing which character in the line we are interpreting
  104. plus = 1 ' variable to hold the amount added to or subtracted from the first accumulator
  105. plus2 = 1 ' variable to hold the amount added to or subtracted from the second accumulator
  106.  
  107. ad = 0 ' sets the first accumulator direction mode 0 =add 1 = subtract
  108. ad2 = 0 ' sets the second accumulator direction mode 0 =add 1 = subtract
  109. mul = 0
  110. mul2 = 0
  111. fm = 0
  112. lem = 0
  113. lem2 = 0
  114. c0 = 0
  115. c1 = 0
  116. c2 = 0
  117. c3 = 0
  118. c4 = 0
  119. c5 = 0
  120. c6 = 0
  121. c7 = 0
  122. c8 = 0
  123. c9 = 0
  124. cat = 0
  125.  
  126. ptjt = 0
  127. ltjt = 0
  128.  
  129. cm = 0 ' variable to hold the comment mode 0 = not the beginning of a comment 1 = beginning of comment
  130. 'The "!" toggles this cm variable
  131.  
  132. COLOR fc, bc: CLS
  133.  
  134. ' This routine is where we get the command line to determine if the user gave the interpretor a file name to work with.
  135.  
  136. filename$ = COMMAND$
  137.  
  138. filename$ = "hello world-6.abcd"
  139.  
  140. load:
  141.  
  142. ' here we load a systems file coded in ABCD itself, to tell the user that a file name is required on the command line.
  143. ' it is for that reason, you can't just click on the ABCD icon and expect to get results.
  144.  
  145. IF filename$ = "" THEN LOCATE 24, 1: PRINT "Usage abcd filename.abcd": END
  146.  
  147. ' We will open the file in sequential access mode and read it in one line at a time
  148.  
  149. OPEN filename$ FOR INPUT AS #1
  150.     x = x + 1
  151.     LINE INPUT #1, prog$(x)
  152.  
  153. tlns = x
  154. x = 1
  155.  
  156. ' now that we have the source code read into the computer's memory,
  157. ' we start at line 1 and we go from the beginning of it to the end of it
  158. ' one character at a time because all commands are single characters in length.
  159. ' We now parse each character so it does not matter if our source code is all
  160. ' on one line, or if it is broken up into many lines.
  161.  
  162.  
  163. parse:
  164.  
  165. m$ = MID$(prog$(ln), p, 1)
  166.  
  167.  
  168. ' Here we do what is necessary if we find a block.
  169. ' The !, @, 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9 characters
  170. ' are block commands. A block must contain one of these
  171. ' commands followed by the required information, and then
  172. ' end with the same command. A comment block starts and
  173. ' ends with the ! character. Everything between the two
  174. ' exclamation points is ignored by the interpretor as it
  175. ' is a comment.
  176.  
  177. IF cm = 1 AND m$ <> "!" THEN GOTO advance
  178. IF cm = 1 AND m$ = "!" THEN cm = 0: GOTO advance
  179.  
  180. IF fm = 0 AND m$ = "%" THEN fm = 1: GOTO advance
  181. IF fm = 1 AND m$ <> "%" THEN nfn$ = nfn$ + m$: GOTO advance
  182. IF fm = 1 AND m$ = "%" THEN fm = 0: GOTO advance
  183.  
  184.  
  185. IF c0 = 0 AND m$ = "0" THEN c1 = 1: GOTO advance
  186. IF c0 = 1 AND m$ <> "0" THEN choice0$ = choice0$ + m$: GOTO advance
  187. IF c0 = 1 AND m$ = "0" THEN c0 = 0: GOTO advance
  188.  
  189. IF c1 = 0 AND m$ = "1" THEN c1 = 1: GOTO advance
  190. IF c1 = 1 AND m$ <> "1" THEN choice1$ = choice1$ + m$: GOTO advance
  191. IF c1 = 1 AND m$ = "1" THEN c0 = 0: GOTO advance
  192.  
  193. IF c2 = 0 AND m$ = "2" THEN c2 = 1: GOTO advance
  194. IF c2 = 1 AND m$ <> "2" THEN choice2$ = choice2$ + m$: GOTO advance
  195. IF c2 = 1 AND m$ = "2" THEN c2 = 0: GOTO advance
  196.  
  197. IF c3 = 0 AND m$ = "3" THEN c3 = 1: GOTO advance
  198. IF c3 = 1 AND m$ <> "3" THEN choice3$ = choice3$ + m$: GOTO advance
  199. IF c3 = 1 AND m$ = "3" THEN c3 = 0: GOTO advance
  200.  
  201. IF c4 = 0 AND m$ = "4" THEN c4 = 1: GOTO advance
  202. IF c4 = 1 AND m$ <> "4" THEN choice4$ = choice4$ + m$: GOTO advance
  203. IF c4 = 1 AND m$ = "4" THEN c4 = 0: GOTO advance
  204.  
  205. IF c5 = 0 AND m$ = "5" THEN c5 = 1: GOTO advance
  206. IF c5 = 1 AND m$ <> "5" THEN choice5$ = choice5$ + m$: GOTO advance
  207. IF c5 = 1 AND m$ = "5" THEN c5 = 0: GOTO advance
  208.  
  209. IF c6 = 0 AND m$ = "6" THEN c6 = 1: GOTO advance
  210. IF c6 = 1 AND m$ <> "6" THEN choice6$ = choice6$ + m$: GOTO advance
  211. IF c6 = 1 AND m$ = "6" THEN c6 = 0: GOTO advance
  212.  
  213. IF c7 = 0 AND m$ = "7" THEN c7 = 1: GOTO advance
  214. IF c7 = 1 AND m$ <> "7" THEN choice7$ = choice7$ + m$: GOTO advance
  215. IF c7 = 1 AND m$ = "7" THEN c7 = 0: GOTO advance
  216.  
  217. IF c8 = 0 AND m$ = "8" THEN c8 = 1: GOTO advance
  218. IF c8 = 1 AND m$ <> "8" THEN choice8$ = choice8$ + m$: GOTO advance
  219. IF c8 = 1 AND m$ = "8" THEN c8 = 0: GOTO advance
  220.  
  221. IF c9 = 0 AND m$ = "9" THEN c9 = 1: GOTO advance
  222. IF c9 = 1 AND m$ <> "9" THEN choice9$ = choice9$ + m$: GOTO advance
  223. IF c9 = 1 AND m$ = "9" THEN c9 = 0: GOTO advance
  224.  
  225. IF cat = 0 AND m$ = ")" THEN cat = 1: cat$ = cat$ + m$: GOTO advance
  226. IF cat = 1 AND m$ <> ")" THEN cat$ = cat$ + m$: GOTO advance
  227. IF cat = 1 AND m$ = ")" THEN c9 = 0: cat$ = cat$ + m$: PRINT cat$;: GOTO advance
  228.  
  229.  
  230.  
  231.  
  232.  
  233.     CASE "$": aom = aom XOR 1
  234.  
  235.     CASE "(": lem = lem XOR 1
  236.  
  237.     CASE "h": aom2 = aom2 XOR 1
  238.  
  239.     CASE "*": ad = ad XOR 1
  240.  
  241.     CASE "&": mul = mul XOR 1
  242.  
  243.     CASE "v": mul2 = mul2 XOR 1
  244.  
  245.     CASE "p": ad2 = ad2 XOR 1
  246.  
  247.     CASE ";": PRINT STR$(acc); " "; CHR$(acc)
  248.  
  249.     CASE "+"
  250.         IF ad = 0 THEN
  251.             acc = acc + plus
  252.         ELSEIF ad = 1 THEN
  253.             acc = acc - plus
  254.         END IF
  255.  
  256.     CASE "x"
  257.         IF mul = 0 THEN
  258.             acc = acc * plus
  259.         ELSEIF mul = 1 THEN
  260.             acc = acc / plus
  261.         END IF
  262.  
  263.     CASE "a"
  264.         IF ad2 = 0 THEN
  265.             acc2 = acc2 + plus
  266.         ELSEIF ad2 = 1 THEN
  267.             acc2 = acc2 - plus
  268.             GOTO advance
  269.         END IF
  270.  
  271.     CASE "d"
  272.         IF mul2 = 0 THEN
  273.             acc2 = acc2 * plus2
  274.         ELSEIF mul2 = 1 THEN
  275.             acc2 = acc2 / plus2
  276.         END IF
  277.  
  278.     CASE ">"
  279.         IF aom = 0 THEN PRINT LTRIM$(STR$(acc));
  280.         IF aom = 1 THEN
  281.             IF acc = 0 OR acc > 255 THEN
  282.                 PRINT LTRIM$(STR$(acc));
  283.             ELSE
  284.                 PRINT CHR$(acc);
  285.             END IF
  286.         END IF
  287.  
  288.     CASE "u"
  289.  
  290.         IF aom2 = 0 THEN PRINT LTRIM$(STR$(acc2));
  291.         IF aom2 = 1 THEN PRINT LTRIM$(CHR$(acc2));
  292.         IF acc2 = 0 OR acc2 > 255 THEN
  293.             PRINT LTRIM$(STR$(acc2));
  294.         ELSE
  295.             PRINT CHR$(acc2);
  296.         END IF
  297.  
  298.     CASE "t"
  299.         IF LEN(STR$(acc)) <> 1 THEN
  300.             acc$ = STR$(acc): accl = LEN(acc$)
  301.             FOR i = accl TO 1 STEP -1
  302.                 tmp$ = tmp$ + MID$(acc$, i, 1)
  303.             NEXT i
  304.             acc = VAL(tmp$)
  305.         END IF
  306.  
  307.     CASE "<"
  308.         IF LEN(STR$(acc)) <> 1 THEN
  309.             acc$ = STR$(acc): accl = LEN(acc$)
  310.             FOR i = accl TO 1 STEP -1
  311.                 tmp$ = tmp$ + MID$(acc$, i, 1)
  312.             NEXT i
  313.             acc = VAL(tmp$)
  314.         END IF
  315.  
  316.  
  317.  
  318.  
  319.     CASE "e"
  320.         IF plus = 1 THEN
  321.             plus = 5
  322.         ELSEIF plus = 5 THEN
  323.             plus = 10
  324.         ELSEIF plus = 10 THEN
  325.             plus = 1
  326.         END IF
  327.  
  328.     CASE "w"
  329.         IF plus2 = 1 THEN
  330.             plus2 = 5: 'GOTO advance
  331.         ELSEIF plus2 = 5 THEN
  332.             plus2 = 10: 'GOTO advance
  333.         ELSEIF plus2 = 10 THEN
  334.             plus2 = 1: 'GOTO advance
  335.         END IF
  336.  
  337.     CASE "f": fc = fc + 1
  338.  
  339.     CASE "g": fc = fc - 1
  340.  
  341.     CASE "b": bc = bc + 1
  342.  
  343.     CASE "c": bc = bc - 1
  344.  
  345.     CASE "|": CLS
  346.  
  347.     CASE "k": fc = 0
  348.  
  349.     CASE "m": bc = 0
  350.  
  351.     CASE "l": ln = 1
  352.  
  353.     CASE "r": acc = 0
  354.  
  355.     CASE "z": acc2 = 0
  356.  
  357.     CASE "o"
  358.         IF fc > 0 AND bc > 0 THEN COLOR fc, bc
  359.         IF fc = 0 AND bc <> 0 THEN COLOR 7, bc
  360.  
  361.     CASE "?"
  362.         getnum:
  363.         RANDOMIZE TIMER
  364.  
  365.         ntg = INT(RND * acc)
  366.         IF ntg > acc THEN GOTO getnum
  367.  
  368.         IF lem = 1 AND ntg < 10 THEN GOTO getnum
  369.         acc = ntg
  370.  
  371.     CASE "i"
  372.         getnum2:
  373.         RANDOMIZE TIMER
  374.  
  375.         ntg2 = INT(RND * acc2)
  376.         IF ntg2 > acc2 THEN GOTO getnum2
  377.         IF lem2 = 1 AND ntg2 < 10 THEN GOTO getnum2
  378.         acc2 = ntg2
  379.  
  380.     CASE "n": PRINT " " ' print a newline
  381.  
  382.     CASE "~"
  383.         getnum3:
  384.         RANDOMIZE TIMER
  385.  
  386.         ntg = INT(RND * 9)
  387.         IF ntg < 0 THEN GOTO getnum3
  388.         IF ntg > 9 THEN GOTO getnum3
  389.         acc = ntg
  390.  
  391.     CASE "^": PRINT " ";
  392.  
  393.     CASE "!": cm = cm XOR 1
  394.  
  395.     CASE "%": fm = fm XOR 1
  396.  
  397.     CASE ""
  398.  
  399.     CASE "0": c0 = c0 XOR 1
  400.  
  401.     CASE "1": c1 = c1 XOR 1
  402.  
  403.     CASE "2": c2 = c2 XOR 1
  404.  
  405.     CASE "3": c3 = c3 XOR 1
  406.  
  407.     CASE "4": c4 = c4 XOR 1
  408.  
  409.     CASE "5": c5 = c5 XOR 1
  410.  
  411.     CASE "6": c6 = c6 XOR 1
  412.  
  413.     CASE "7": c7 = c7 XOR 1
  414.  
  415.     CASE "8": c8 = c8 XOR 1
  416.  
  417.     CASE "9": c9 = c9 XOR 1
  418.  
  419.     CASE ")": cat = cat XOR 1
  420.  
  421.         ' This is the routine where we wait for the user to press only the keys 0-9, nad thehn we load a new source code based on what they chose.
  422.         ' There must be at least one choice block in your code, otherwise the interpretor does not have any source code file to interpret at that
  423.         ' point and will crash.
  424.  
  425.     CASE "K"
  426.         DO
  427.             z$ = INKEY$
  428.             _LIMIT 30 'play nice with your CPU and other apps while waiting on the user to press their key
  429.         LOOP UNTIL z$ >= "0" AND z$ <= "9"
  430.         IF z$ = "0" THEN filename$ = choice0$
  431.         IF z$ = "1" THEN filename$ = choice1$
  432.         IF z$ = "2" THEN filename$ = choice2$
  433.         IF z$ = "3" THEN filename$ = choice3$
  434.         IF z$ = "4" THEN filename$ = choice4$
  435.         IF z$ = "5" THEN filename$ = choice5$
  436.         IF z$ = "6" THEN filename$ = choice6$
  437.         IF z$ = "7" THEN filename$ = choice7$
  438.         IF z$ = "8" THEN filename$ = choice8$
  439.         IF z$ = "9" THEN filename$ = choice9$
  440.         GOTO load
  441.  
  442.     CASE "H": PRINT "hello world";
  443.  
  444.  
  445.         ' go up a line of code
  446.     CASE "j", "J", "s", "S"
  447.         '    this is a cursor command
  448.         IF NOT MovingCursor(ln, p, prog$(ln), tlns) THEN PRINT "Error in move commands' line" ELSE GOTO parse
  449.  
  450.         ' IF ln = 1 THEN
  451.         ' GOTO advance2
  452.         ' END IF
  453.  
  454.         ' IF ptmt = 0 AND ltmt = 0 THEN
  455.         ' ptmt = p
  456.         ' ltmt = ln
  457.         ' END IF
  458.  
  459.  
  460.         '  ltmt = ltmt - 1
  461.  
  462.         ' go down a line of code
  463.  
  464.         '    CASE "J"
  465.         ' this is a cursor command
  466.  
  467.  
  468.         '  IF ln = tlns THEN
  469.         '  GOTO advance2
  470.         '  END IF
  471.  
  472.         ' IF ln = 50000 THEN
  473.         ' GOTO advance2
  474.         ' END IF
  475.  
  476.         ' IF ptmt = 0 AND ltmt = 0 THEN
  477.         '  ptmt = p
  478.         '  ltmt = ln
  479.         '  END IF
  480.  
  481.         '       ltmt = ltmt + 1
  482.  
  483.         ' go left one character within the current line
  484.         '  CASE "s"
  485.         ' this is a cursor command
  486.  
  487.  
  488.         '  IF p = 1 THEN
  489.         '  GOTO advance
  490.         '   END IF
  491.  
  492.         '  IF ptmt = 0 AND ltmt = 0 THEN
  493.         '  ptmt = p
  494.         '  ltmt = ln
  495.         '   END IF
  496.  
  497.         '  ptmt = ptmt - 1
  498.  
  499.         ' go right one character within the current line
  500.  
  501.         ' CASE "S"
  502.         ' this is a cursor command
  503.  
  504.  
  505.         ' IF p = LEN(prog$(ln)) THEN
  506.         ' GOTO advance
  507.         ' END IF
  508.  
  509.         ' IF ptmt = 0 AND ltmt = 0 THEN
  510.         '  ptmt = p
  511.         ' ltmt = ln
  512.         ' END IF
  513.  
  514.         ' ptmt = ptmt + 1
  515.  
  516.  
  517.     CASE "/"
  518.         p = ptmt
  519.         ln = ltmt
  520.         GOTO parse
  521.  
  522.  
  523.     CASE "\": END
  524.  
  525.     CASE ELSE ' This routine ignores everytthing else that is not a command and just moves on.
  526.  
  527.  
  528. ' The routines advance is where we move to the next character in the string that is the current line of code
  529. ' When we reach the end of the line, the advance2 routine moves to the next line and reset the position to the
  530. ' first character and start from there.
  531.  
  532. advance:
  533.  
  534. p = p + 1
  535. IF p >= LEN(prog$(ln)) + 1 THEN GOTO advance2
  536. GOTO parse
  537.  
  538. advance2:
  539. ln = ln + 1: p = 1
  540. IF ln = tlns + 1 AND nfn$ = "" THEN
  541.     END
  542.  
  543. IF ln = 50001 AND nfn$ = "" THEN END
  544.  
  545. IF ln = tlns + 1 AND nfn$ <> "" THEN
  546.     filename$ = nfn$: nfn$ = "": x = 0: p = 1: ln = 1: GOTO load
  547.  
  548. IF ln = 50001 AND nfn$ <> "" THEN
  549.     filename$ = nfn$: nfn$ = "": x = 0: p = 1: ln = 1: GOTO load
  550. GOTO parse
  551.  
  552. END ' this is only a logic end because the previouse line of code never arrives here!
  553.  
  554. FUNCTION MovingCursor (ln, p, LC$, TLines)
  555.     ' parser of cursor metacommand
  556.     MovingCursor = 0 ' no moving commands
  557.  
  558.     ' we preserve the value of parameters
  559.     cursor = p
  560.     lines = ln
  561.     Codex$ = LC$
  562.     lCursor = 0 'local cursor of line of moving commands
  563.  
  564.     'parsing the line of code for command of move cursor
  565.     DO
  566.         lCursor = lCursor + 1
  567.         MoveCursor$ = MID$(Codex$, lCursor, 1)
  568.         ' these commands don't let go out of range as showed in the main
  569.         ' so if you have the cursor at point 30 and you go back for 32 times
  570.         ' you'll be at position 1 of the line and not to the previous line of code
  571.         ' in the same manner for going up or down the lines of code
  572.  
  573.         SELECT CASE MoveCursor$
  574.             CASE "j" ' up
  575.                 IF lines > 1 THEN lines = lines - 1
  576.             CASE "J" 'down
  577.                 IF lines < 50000 AND lines < TLines THEN lines = lines + 1
  578.             CASE "s" 'left
  579.                 IF cursor > 1 THEN cursor = cursor - 1
  580.             CASE "S" 'right
  581.                 cursor = cursor + 1
  582.         END SELECT
  583.     LOOP WHILE INSTR("jJsS", MoveCursor$) AND lCursor <= LEN(Codex$)
  584.  
  585.  
  586.     ' we put back the value of cursor to execut normal commands
  587.     p = cursor
  588.     ln = lines
  589.     MovingCursor = -1 ' function has worked without error
  590.  

and here your sorgent
Code: [Select]
!This program prints hello and then jumps to another part of the program to print world then jumps back to print again!

|$ee+++++++e++>
*+++>
*+++++++>>
+++>^
JJJJsssssSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS

+++>*++++++>*++++++>*++++++++>+++++>$\
                                     
                                      ++++++++>*++++++++>*+++>*++++++>++++++++>
jjjssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss

Now I can take a look at your news
Title: Re: Need help with my abcd program
Post by: TempodiBasic on October 03, 2019, 05:26:58 pm
New version no code!

Ok compiler is secret!

with the absolute path into the .exe who have another path gets only errors!

Thanks to share, please no more exe for me.