Author Topic: Need help with my abcd program  (Read 7108 times)

0 Members and 1 Guest are viewing this topic.

Offline Larryrl

  • Newbie
  • Posts: 26
    • View Profile
Need help with my abcd program
« 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   
« Last Edit: October 01, 2019, 04:44:26 pm by Larryrl »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Need help with my abcd program
« Reply #1 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!
« Last Edit: September 30, 2019, 06:11:31 pm by TempodiBasic »
Programming isn't difficult, only it's  consuming time and coffee

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Need help with my abcd program
« Reply #2 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.

Offline Larryrl

  • Newbie
  • Posts: 26
    • View Profile
Re: Need help with my abcd program
« Reply #3 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.
« Last Edit: October 01, 2019, 04:51:48 pm by Larryrl »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Need help with my abcd program
« Reply #4 on: October 01, 2019, 05:47:02 pm »
Hi
this is the link in your .BAS
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:\
Programming isn't difficult, only it's  consuming time and coffee

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Need help with my abcd program
« Reply #5 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!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Need help with my abcd program
« Reply #6 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

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


Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Need help with my abcd program
« Reply #7 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
Programming isn't difficult, only it's  consuming time and coffee

Offline Larryrl

  • Newbie
  • Posts: 26
    • View Profile
Re: Need help with my abcd program
« Reply #8 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
 

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Need help with my abcd program
« Reply #9 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.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Need help with my abcd program
« Reply #10 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. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Larryrl

  • Newbie
  • Posts: 26
    • View Profile
Re: Need help with my abcd program
« Reply #11 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

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Need help with my abcd program
« Reply #12 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?
Programming isn't difficult, only it's  consuming time and coffee

Offline Larryrl

  • Newbie
  • Posts: 26
    • View Profile
Re: Need help with my abcd program
« Reply #13 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.   

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.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Need help with my abcd program
« Reply #14 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
 
ABCD.bas vs ABCD2.bas.jpg

 
ABCD.bas vs ABCD2.BAS.jpg
Programming isn't difficult, only it's  consuming time and coffee