Executing actual commands

I want the recognized keywords to be actual commands, to call some function to perform - like PRINT "Hello, World" should actually print Hello, World to the console.

In lieu of namespaces I’ll name each function kw_*keyword*, like kw_print for PRINT, kw_input for INPUT and so on.

The function should receive the remainder of the inputline - everything after the keyword - so it has some parameters, something to print.

So, a very very simple (and very hardcoded) keyword-handler after a keyword is recognized, could be:

// after printf("Recognized keyword ...
	switch (kw)
	{
	case 5:
	  kw_let(inp + strlen(keywords[kw]));
	  break;
	case 6:
	  kw_print(inp + strlen(keywords[kw]));
	  break;
	case 7:
	  kw_input(inp + strlen(keywords[kw]));
	
	default:
	  break;
	}

And the commands themselves could be as simple as:

void kw_let(char *parm)
{
  printf("LET %s\\n", parm);
}

void kw_print(char *parm)
{
  printf("PRINT %s\\n", parm);
}

void kw_input(char *parm)
{
  printf("INPUT %s\\n", parm);
}

Now I want something to actually happen in each command

Implementing PRINT

First, eventual whitespace between the keyword and the string to be printed should be ignored

  while (*parm == ' ' || *parm == '\\t')
      parm++;

Then we look for a " to start the string, and then another " to end it …

	// find start and end of string
	char* start = parm;
	while(*start != '"') start++;
	start++;
	char* end = start;
	while(*end != '"') end++;

Now we have two pointers - and to keep it simple I’ll just put each character between those two pointers, to the screen:

  while(start < end)
  {
    putchar(*start);
    start++;
  }

This sort of works:

The bright green text is the one printed by PRINT - the rest is debugging-info.

The bright green text is the one printed by PRINT - the rest is debugging-info.