X-Git-Url: http://git.subgeniuskitty.com/vvhitespace/.git/blobdiff_plain/b8b65c17f7c4cfbe7f1d2f6b76580d40afe51526..f10da6e3fe5928f0d15bc71487a4591e1fb2dbff:/vv_compiler.c diff --git a/vv_compiler.c b/vv_compiler.c index 9944070..e53f70d 100644 --- a/vv_compiler.c +++ b/vv_compiler.c @@ -25,9 +25,9 @@ print_usage(char ** argv) ); } -/* Allows building an ASCII string on the stack. */ -/* This syntax: A"test" */ -/* Results in five PUSH_IMMEDIATE commands for the four letters and newline. */ +/* Builds an ASCII string on the stack using VVS PUSH_IMMEDIATE commands. */ +/* The syntax: A"test" results in six PUSH_IMMEDIATE commands for the four */ +/* letters, newline, and null-terminator. */ /* Expects 'input' to present a double-quoted ('"') ASCII string. */ /* The 'A' has already been chomped. */ void @@ -35,7 +35,11 @@ parse_ascii_string(FILE * input, FILE * output) { uint8_t temp_byte; fread(&temp_byte, 1, 1, input); - if (temp_byte != '"') fprintf(stderr, "WARNING: Expected double-quote to begin string.\n"); + if (temp_byte != '"') { + /* Die here since we walk the string backward and look for '"' as a terminator. */ + fprintf(stderr, "ERROR: Expected double-quote to begin string.\n"); + exit(EXIT_FAILURE); + } /* Put the letters on the stack in reverse. Don't forget to put a null-terminator first. */ for (fread(&temp_byte,1,1,input); temp_byte != '"'; fread(&temp_byte,1,1,input)) continue; @@ -45,7 +49,7 @@ parse_ascii_string(FILE * input, FILE * output) /* First, push three spaces to start a PUSH_IMMEDIATE command for a positive number. */ uint8_t temp_output = ' '; for(int i=0;i<3;i++) fwrite(&temp_output, 1, 1, output); - /* Second, push the ASCII character, 7 bits total, most signficant bit first. */ + /* Second, push the ASCII character, 7 bits total, most significant bit first. */ /* Remember, [Tab]=1 and [Space]=0. */ uint8_t index = 7; /* 7 bits needed per ASCII character. */ while (index) {