Yab to C converter
#7
(01-14-2021, 10:05 AM)bbjimmy Wrote: Any progress? this would be great!
Sorry about the late response.  I'm trying to stick to one project at a time.  I'm certain it is possible to do.  I just recently got a day job but with some help, I'm certain it's possible.  The hard part is finding the time to figure it out.

The central aspect of the runtime consists of an intrusive singly linked list stack as a base class.  The activation records of each function extend that base class by creating a record of all the local variables.  Because function definitions can't be nested inside each other in Yab, the definitions will be written one after another in the call_stack.h file.

The global definitions extend a class containing the stack pointer and any other static runtime states.  This gets written to the heap.h file.

The actual executable code gets written to the main.cpp file.  However, since some BASIC commands are not strictly structured ordering we can't use structured C++ as a representation of them and therefore are implemented as labels and branches.  The way to do that in C++ is to use a simple state machine.  The runtime errors are defined as a list of consecutive constants and every additional state is an extension of that list.  The error constants along with all nonvariants of compilation are in a fixed header called yabcompile.h and the additional states are written to states.h as we go.

This only leaves the state machine itself.  It will be formatted as a while loop containing a switch statement.  The case commands within the switch statement will signify the destination labels.  A jump statement is represented by assigning a label constant to the state variable and issuing a break statement.  This loops back through the while loop reentering the switch statement.  An example main.cpp file might look something like this:
Quote:while (state>endWithoutError) {
   switch (state) {
      case start:
         var1=0;
      case do1:
         printf("var1=%d\n", var1);
         var1=var1+1;
         if(var1<10) {
            state=do1;
            break;
         }
         state=endWithoutErrors;
         break;
     }
}
That should give you an idea how this can work.
Reply


Messages In This Thread
Yab to C converter - by SamuraiCrow - 10-05-2018, 12:53 PM
RE: Yab to C converter - by bbjimmy - 10-06-2018, 09:42 AM
RE: Yab to C converter - by SamuraiCrow - 12-28-2020, 03:50 PM
RE: Yab to C converter - by SamuraiCrow - 10-10-2018, 11:08 PM
RE: Yab to C converter - by SamuraiCrow - 10-21-2018, 02:32 PM
RE: Yab to C converter - by bbjimmy - 01-14-2021, 10:05 AM
RE: Yab to C converter - by SamuraiCrow - 02-25-2021, 12:43 AM
RE: Yab to C converter - by SamuraiCrow - 02-25-2021, 09:54 PM
RE: Yab to C converter - by lorglas - 02-26-2021, 11:03 AM
RE: Yab to C converter - by SamuraiCrow - 02-26-2021, 03:35 PM
RE: Yab to C converter - by bbjimmy - 02-26-2021, 06:38 PM
RE: Yab to C converter - by SamuraiCrow - 03-09-2021, 10:10 PM
RE: Yab to C converter - by SamuraiCrow - 03-13-2021, 05:36 PM
RE: Yab to C converter - by bbjimmy - 03-14-2021, 08:35 AM
RE: Yab to C converter - by SamuraiCrow - 03-14-2021, 09:55 PM
RE: Yab to C converter - by SamuraiCrow - 03-18-2021, 08:04 AM
RE: Yab to C converter - by bbjimmy - 03-19-2021, 08:12 AM
RE: Yab to C converter - by SamuraiCrow - 03-19-2021, 06:30 PM
RE: Yab to C converter - by bbjimmy - 03-20-2021, 08:59 AM
RE: Yab to C converter - by SamuraiCrow - 03-20-2021, 09:53 AM
RE: Yab to C converter - by SamuraiCrow - 03-24-2021, 05:21 PM
RE: Yab to C converter - by bbjimmy - 03-24-2021, 05:35 PM
RE: Yab to C converter - by SamuraiCrow - 03-27-2021, 01:07 PM
RE: Yab to C converter - by bbjimmy - 03-27-2021, 01:36 PM
RE: Yab to C converter - by SamuraiCrow - 03-29-2021, 01:54 PM
RE: Yab to C converter - by bbjimmy - 03-29-2021, 06:12 PM
RE: Yab to C converter - by SamuraiCrow - 03-30-2021, 05:26 PM
RE: Yab to C converter - by SamuraiCrow - 04-07-2021, 12:07 PM
RE: Yab to C converter - by bbjimmy - 04-08-2021, 11:05 AM
RE: Yab to C converter - by SamuraiCrow - 04-08-2021, 03:58 PM
RE: Yab to C converter - by SamuraiCrow - 04-12-2021, 08:05 PM
RE: Yab to C converter - by SamuraiCrow - 04-16-2021, 09:10 PM
RE: Yab to C converter - by bbjimmy - 04-17-2021, 07:43 AM
RE: Yab to C converter - by SamuraiCrow - 04-21-2021, 08:26 PM
RE: Yab to C converter - by SamuraiCrow - 04-30-2021, 04:44 AM
RE: Yab to C converter - by lorglas - 04-30-2021, 01:38 PM
RE: Yab to C converter - by bbjimmy - 05-01-2021, 09:58 AM
RE: Yab to C converter - by SamuraiCrow - 05-01-2021, 09:55 PM
RE: Yab to C converter - by SamuraiCrow - 05-05-2021, 09:03 PM
RE: Yab to C converter - by SamuraiCrow - 06-28-2022, 08:13 PM
RE: Yab to C converter - by bbjimmy - 07-06-2022, 12:43 PM
RE: Yab to C converter - by SamuraiCrow - 07-31-2022, 06:22 PM
RE: Yab to C converter - by SamuraiCrow - 08-01-2022, 02:42 PM
RE: Yab to C converter - by SamuraiCrow - 08-05-2022, 09:46 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)
Free Web Hosting