Author Topic: Compiled language for BASIC programmers  (Read 3931 times)

0 Members and 1 Guest are viewing this topic.

Offline J_Walker87

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 7
  • Rating: +1/-0
    • View Profile
Compiled language for BASIC programmers
« on: July 02, 2021, 06:13:48 pm »
Hey, I just finished learning the basics of ASM programming using Mimas (thanks, by the way, for the recommendation to use Mimas if you're reading this post and replied to my post about on-calc ASM programming). I just got a link cable about a month before starting to learn ASM, and I remember it really sucked not being able to download and upload programs. However, I noticed that lots of people without link cables just type in programs from source listings. My idea is to make programming easier for people without link cables by designing a compiled language that is compiled by a BASIC program into an assembly program. Using Xeda's awesome programs, tools, and documentation for hex assembly I was able to start on writing a compiler in BASIC to compile a language similar to Tiny BASIC (see https://en.wikipedia.org/wiki/Tiny_BASIC).

I have two questions:
1. Is there an existing optimized routine that will find all occurrences of a string in another string and replace that each occurrence of that string with another string? Example: Input: "hello", "l", "LL" Output: "heLLLLo"
2. Does anyone have suggestions for languages other than Tiny BASIC style languages that would be easy to learn and easy to compile.

Edit: the idea is to have something like Axe except the compiler is in BASIC so you can type it in. It will also be less powerful most likely. I realized I was a little vague in my idea.
« Last Edit: July 02, 2021, 06:18:45 pm by J_Walker87 »

Offline E37

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +23/-0
  • Trial and error is the best teacher
    • View Profile
Re: Compiled language for BASIC programmers
« Reply #1 on: July 02, 2021, 07:00:36 pm »
If I understand what you are saying, you are trying to make a basic program that compiles another program to assembly. Are you using some kind of library/shell or how are you reading files in basic? Do you plan on having some small hex libraries? Also, I would imagine that the time needed to type in a whole compiler in by hand would be huge and the likelihood of the user making a mistake would be high. Debugging an assembly/compiled program can be tricky enough to a new user without having to worry if they had a small typo somewhere in the 10k+ bytes of the compiler program. While I won't dissuade you from the project, there seems to be some pretty huge difficulties involved. Additionally, you probably have a pretty small audience. How many people do you think would be interested enough in the language to spend hours copying it over by hand (assuming they don't have a cable)?

As for the optimized routine, what language do you want it in? Since you say strings I assume you mean basic.
I'm still around... kind of.

Offline NonstickAtom785

  • LV3 Member (Next: 100)
  • ***
  • Posts: 78
  • Rating: +4/-0
  • Just live life. Cal-cu-lat-or style!
    • View Profile
Re: Compiled language for BASIC programmers
« Reply #2 on: July 02, 2021, 08:07:56 pm »
I think what you're asking is a bit problematic. For one, to make a program that compiles another program with TI-BASIC would require a stupid amount of space on the calculator. We already have AXE which combines both z80 ASM and TI Basic with the native on-calc editor. Additionally we have Grammer. I've typed up whole 10k+ byte games in those syntax's for that purpose.


I also see what you're saying. Without a link cable people can't get these. Not easily at least. But to make a compiler with TI-BASIC, would require you to,


A: make a library with every single instruction the z80 chipset has to offer and add the equivalent HEX values and index them using form of string manipulation from another program.
B: Make an entire system for checking any symtax errors.
C: and now that I think about it you can't really parse the data in another BASIC program without having an ASM program to convert it all to string.


I hope you try this though. Best of luck to you if you do.
Grammer2 is Good!

Offline J_Walker87

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 7
  • Rating: +1/-0
    • View Profile
Re: Compiled language for BASIC programmers
« Reply #3 on: July 02, 2021, 09:17:40 pm »
If I understand what you are saying, you are trying to make a basic program that compiles another program to assembly. Are you using some kind of library/shell or how are you reading files in basic? Do you plan on having some small hex libraries? Also, I would imagine that the time needed to type in a whole compiler in by hand would be huge and the likelihood of the user making a mistake would be high. Debugging an assembly/compiled program can be tricky enough to a new user without having to worry if they had a small typo somewhere in the 10k+ bytes of the compiler program. While I won't dissuade you from the project, there seems to be some pretty huge difficulties involved. Additionally, you probably have a pretty small audience. How many people do you think would be interested enough in the language to spend hours copying it over by hand (assuming they don't have a cable)?
Yes, the idea is to have a BASIC program that compiles another program to assembly. The program to be compiled to a hex string, which the user can copy into a program using [2nd](Rcl). (I could change this to make it more convenient using a simple hex code, which I'll probably end up doing if the project works out). And yes, I do plan on using a couple small hex libraries. Also, I don't think it will be 10kB. Tiny BASIC is designed to fit into 2 or 3 kilobytes of memory. I'll have to modify the original language to allow the user to call assembly routines in a library style in order to give the language graphics capabilities among other things. Also, based on my experience in the Ti-BASIC Dev forms, people are often willing to type in a 2 or 3 kilobyte program by hand if they have the source. Multiple people have asked for the source code of several kilobyte games and then typed them in over on the form. Next, I have no idea who my audience would be. I know that if someone else did this and I didn't have a link cable I would be interested, but I don't know about everyone else.
As for the optimized routine, what language do you want it in? Since you say strings I assume you mean basic.
If it's short, assembly would be fine. However, if there's a Ti-BASIC routine for it that isn't too long, that would be fine. I'm also working on making routines myself. I often find however that other people can usually come up with something more efficient.
A: make a library with every single instruction the z80 chipset has to offer and add the equivalent HEX values and index them using form of string manipulation from another program.
B: Make an entire system for checking any symtax errors.
C: and now that I think about it you can't really parse the data in another BASIC program without having an ASM program to convert it all to string.
A: I don't think I'd have to do this if I used hex for everything. I do plan to make a system that handles labels and relative jumps, however.
B: I thought about this and figured I may have to just use vague error handling. However, Tiny BASIC programs are usually pretty easy to find syntax errors in if you know the line number.
C:Yeah, I get what you mean. Instead of storing the program in a program variable, I could use a string. Editing Tiny BASIC programs is very simple, and Ti-BASIC could easily handle that kind of string editing. To get a feel for Tiny BASIC, check out a different BASIC dialect, MS-BASIC, at https://www.masswerk.at/pet/.

Also, I do realize this would be difficult. However, so far it's going really well. So far I've already made a subprogram in Ti-BASIC to compile math expressions into assembly.

Finally, I need help with one more thing (currently, I mean. In the near future I'll probably have more questions). I am pretty new to assembly, so this may sound dumb, but what's the best way to load the value at a pointer into the 'b' register (like 'ld a, (**)', but instead with the 'b' register).

Offline NonstickAtom785

  • LV3 Member (Next: 100)
  • ***
  • Posts: 78
  • Rating: +4/-0
  • Just live life. Cal-cu-lat-or style!
    • View Profile
Re: Compiled language for BASIC programmers
« Reply #4 on: July 02, 2021, 09:25:32 pm »
Code: [Select]
push af
ld a,(**)
ld b,a
pop af
If you don't need to save the a register you can remove the push and pop.

Additionally if you do not want to use the a register you can do the following:
Code: [Select]
ld b,(hl)A little different but works with DE:
Code: [Select]
ex de,hl
ld b,(hl)
ex de,hl
« Last Edit: July 02, 2021, 09:32:16 pm by NonstickAtom785 »
Grammer2 is Good!

Offline J_Walker87

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 7
  • Rating: +1/-0
    • View Profile
Re: Compiled language for BASIC programmers
« Reply #5 on: July 02, 2021, 09:50:21 pm »
Okay, thanks for the routine.

Also, for anyone who cares, this is how the program to compile math expressions works:
Example: Compile "2+3*4-X" to assembly (Note: X is a variable, and all math is 8 bit for simplicity. Also there's no order of operations or parentheses. I think this is fine though since I'm aiming for compiler simplicity.)
The expression compiler would produce the following code, but in hex format:
Code: [Select]
ld a,2
add a,3
ld b,4
call MulAB           ;MulAB is a multiply routine label
ld hl,X              ;X is a label for the variable X
sub (hl)
Let me know if I can improve this somehow.