diff options
author | Alex AUVOLAT <alexis211@gmail.com> | 2013-06-08 23:09:52 +0200 |
---|---|---|
committer | Alex AUVOLAT <alexis211@gmail.com> | 2013-06-08 23:09:52 +0200 |
commit | 4d65fcb9a8b6c7c6fd5a3390c46a96d11b6a80d4 (patch) | |
tree | c193acf64ff2db985f6664f161cf586c3caeb684 /src/user/app/kbasic/commands.c | |
parent | eae9997d3c2dbaef53022ddabe61c1800a619499 (diff) | |
download | TCE-4d65fcb9a8b6c7c6fd5a3390c46a96d11b6a80d4.tar.gz TCE-4d65fcb9a8b6c7c6fd5a3390c46a96d11b6a80d4.zip |
All FWIK is deleted. YOSH is now pure C. Not-working KBASIC included.
Diffstat (limited to 'src/user/app/kbasic/commands.c')
-rw-r--r-- | src/user/app/kbasic/commands.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/user/app/kbasic/commands.c b/src/user/app/kbasic/commands.c new file mode 100644 index 0000000..f60f32a --- /dev/null +++ b/src/user/app/kbasic/commands.c @@ -0,0 +1,103 @@ +#include <stdio.h> +#include <string.h> +#include <ctype.h> + +#include "basic.h" + +/* Assign a variable a value. */ +void assignment() +{ + int *var; + int value; + + /* get the variable name */ + get_token(); + if(!isalpha(*token)) { + serror(4); + return; + } + + var = find_var(token); + + /* get the equals sign */ + get_token(); + if(*token!='=') { + serror(3); + return; + } + + /* get the value to assign to var */ + get_exp(&value); + + /* assign the value */ + *var = value; +} + + + +/* Execute a simple version of the BASIC PRINT statement */ +void exec_print() +{ + int answer; + int len=0, spaces; + char last_delim; + + do { + get_token(); /* get next list item */ + if(tok==EOL || tok==FINISHED) break; + if(token_type==QUOTE) { /* is string */ + printf("%s", token); + len += strlen(token); + get_token(); + } + else { /* is expression */ + putback(); + get_exp(&answer); + get_token(); + len += printf("%d", answer); + } + last_delim = *token; + + if(*token==';') { + /* compute number of spaces to move to next tab */ + spaces = 8 - (len % 8); + len += spaces; /* add in the tabbing position */ + while(spaces) { + printf(" "); + spaces--; + } + } + else if(*token==',') /* do nothing */; + else if(tok!=EOL && tok!=FINISHED) serror(0); + } while (*token==';' || *token==','); + + if(tok==EOL || tok==FINISHED) { + if(last_delim != ';' && last_delim!=',') printf("\n"); + } + else serror(0); /* error is not , or ; */ + +} + +/* Execute a simple form of the BASIC INPUT command */ +void input() +{ + int *var; + int tmp; + + get_token(); /* see if prompt string is present */ + if(token_type==QUOTE) { + printf("%s", token); /* if so, print it and check for comma */ + get_token(); + if(*token!=',') serror(1); + get_token(); + } + else printf("? "); /* otherwise, prompt with / */ + + var = find_var(token); /* get the input var */ + + scanf("%d\n", var); /* read input */ + + /* flush input */ + while ((tmp = getchar()) != '\n' && tmp != EOF); +} + |