Author Topic: Select case help  (Read 4467 times)

0 Members and 1 Guest are viewing this topic.

Offline Larryrl

  • Newbie
  • Posts: 26
    • View Profile
Select case help
« on: October 26, 2021, 03:13:41 pm »
Ok, so I am designing my own programming language in qb64, using subs. I have a selecct case type command as well as a case type command and an end select type command. I plan on adding a case else type command at some point.

Therein lies the problem. The language is interpreted so my lexer/parser checks for tokens and parses the tokens seperate from the rest of the line of code. Now, I call a specific sub for each command in my language. I can call a sub for the select case type command, but as we all know, it has multiple parts to it.

If when the qb64 source code says select case var in the sub, do I have to include the case "whatever" after it for the compiler to detect it, or can that part be in another sub?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Select case help
« Reply #1 on: October 26, 2021, 03:55:25 pm »
Not sure what your asking but I remember being told that Select Case in QB64 is really an IF... ElseIf... Else... End IF block in C++ and there is reason they call it a block, it can not be broken or split.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Select case help
« Reply #2 on: October 26, 2021, 04:16:11 pm »
If you are building an interpreter, you know your commands mapper will be looking for that end select or end x where x is the end of any block of code to know where to goto after the case or else if block or exit loop is located. That would be lost if that was in another module or subroutine.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Select case help
« Reply #3 on: October 26, 2021, 04:19:15 pm »
The elseif cases are optional as the else cases just like QB64 allows.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Select case help
« Reply #4 on: October 26, 2021, 04:48:25 pm »
@blpus I'm surprised Rob went with IF THEN ELSEIF instead of just using SWITCH, which is so similar to BASIC SELECT CASE. Anyway, it worked.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Larryrl

  • Newbie
  • Posts: 26
    • View Profile
Re: Select case help
« Reply #5 on: October 27, 2021, 10:00:58 am »
Not sure what your asking but I remember being told that Select Case in QB64 is really an IF... ElseIf... Else... End IF block in C++ and there is reason they call it a block, it can not be broken or split.

Ok, so I will go back to my original source code, and make it a transpiler instead of an interpretor. I can trans compile my maroon language code into qb64 source code and then compile it in qb64. That is all I know how to do. I know a little C C++ and c#, but I program better in basic. I will still work on the interpreted version, but just leave out the commands that cannot be implemented.

Thanks

Offline Larryrl

  • Newbie
  • Posts: 26
    • View Profile
Re: Select case help
« Reply #6 on: October 27, 2021, 10:12:04 am »
If you are building an interpreter, you know your commands mapper will be looking for that end select or end x where x is the end of any block of code to know where to goto after the case or else if block or exit loop is located. That would be lost if that was in another module or subroutine.

Actually If I'm being honest, I do not know what a commands mapper is, or does. I might have programmed one into this project, and just not know it. My keywords end in a colon, and I seperate the line of code there, into a keyword, and whatever came after it.  Then I use if then statements to detect which keyword was found, and I call a sub with the same name as my keyword minus the colon of course, and it handles what to do with any parameters needed by the command. Then it should move on to the next line of source code code.

Thanks for the help. I will attack this problem a different way.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Select case help
« Reply #7 on: October 27, 2021, 11:12:35 am »
Sorry "Commands mapper" is very poor term.

I was talking about a sort of map of where to go, what line number, when execution needed to jump and did not proceed downward through the lines of code by default.

Actually during run time of a interpreted program the interpreter can look for the end of a loop (or start) or other block marker without mapping it all out ahead of time. I found it easier to map out the end of blocks or starts of loops or returns from GoSubs, End If particularly when trying to handle any given amount of ElseIf blocks plus a possible Else block.


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Select case help
« Reply #8 on: October 27, 2021, 11:19:53 am »
@Larryrl

Have you gotten to point where you allow user to make SUBs and FUNCTIONs (or something similar) for his program?

That's where I am stuck, I've got GoSubs but not user defined Subs and or Functions.