Added the ability to parse commands as well as expressions.
Added basic PRINT and REM commands. Added solver tests which had been around for a while and not committed. All execution is still immediate mode.
This commit is contained in:
@@ -8,13 +8,14 @@
|
||||
int main(void)
|
||||
{
|
||||
struct basic_expr *expr;
|
||||
char *line;
|
||||
/*struct basic_line *retline;
|
||||
struct basic_line *arrayline;*/
|
||||
|
||||
/* Store a line */
|
||||
/* expr = basic_parse_expr("10 =1 + 1");
|
||||
if ( expr == NULL ) return 1;
|
||||
if ( expr->lval_type != BASIC_LVAL_CONST ) return 2;
|
||||
if ( expr->lval_type != BASIC_LVAL_CONST_INT ) return 2;
|
||||
if ( expr->rval_type != BASIC_RVAL_PTR ) return 3;
|
||||
if ( expr->lval.i != 10 ) return 4;
|
||||
if ( expr->rval.ptr == NULL ) return 5;
|
||||
@@ -25,12 +26,49 @@ int main(void)
|
||||
expr = basic_parse_expr(retline->content);*/
|
||||
expr = basic_parse_expr("1 + 1");
|
||||
if ( expr == NULL ) return 7;
|
||||
if ( expr->lval_type != BASIC_LVAL_CONST ) return 8;
|
||||
if ( expr->rval_type != BASIC_RVAL_CONST ) return 9;
|
||||
if ( expr->lval_type != BASIC_LVAL_CONST_INT ) return 8;
|
||||
if ( expr->rval_type != BASIC_RVAL_CONST_INT ) return 9;
|
||||
if ( expr->lval.i != 1 ) return 10;
|
||||
if ( expr->rval.i != 1 ) return 11;
|
||||
if ( expr->type != BASIC_OPTP_ADD ) return 12;
|
||||
|
||||
line = "REM This is a comment that gets ignored";
|
||||
expr = basic_parse_expr(line);
|
||||
printf("%s\n", line);
|
||||
printf("token = %s\n", tokenizer_token());
|
||||
printf("errno = %d\n", basic_errno);
|
||||
if ( expr == NULL ) return 13;
|
||||
if ( expr->type != BASIC_OPTP_CMD ) return 14;
|
||||
if ( expr->lval_type != BASIC_LVAL_CMDPTR ) return 15;
|
||||
if ( expr->lval.cmd_ptr != &basic_cmd_rem ) return 16;
|
||||
|
||||
line = "PRINT 10";
|
||||
expr = basic_parse_expr(line);
|
||||
printf("%s\n", line);
|
||||
printf("token = %s\n", tokenizer_token());
|
||||
printf("errno = %d\n", basic_errno);
|
||||
printf("rval.ptr = '%s'\n", (char *)expr->rval.ptr);
|
||||
if ( expr == NULL ) return 17;
|
||||
if ( expr->type != BASIC_OPTP_CMD ) return 18;
|
||||
if ( expr->lval_type != BASIC_LVAL_CMDPTR ) return 19;
|
||||
if ( expr->lval.cmd_ptr != &basic_cmd_print ) return 20;
|
||||
if ( expr->rval_type != BASIC_RVAL_PTR ) return 21;
|
||||
if ( expr->rval.ptr == NULL ) return 22;
|
||||
if ( strcmp((char *)expr->rval.ptr, " 10") != 0 ) return 23;
|
||||
|
||||
line = " 10"; /* ... continuing logic from the previous */
|
||||
expr = basic_parse_expr(line);
|
||||
printf("%s\n", line);
|
||||
printf("token = %s\n", tokenizer_token());
|
||||
printf("errno = %d\n", basic_errno);
|
||||
printf("expr.type = %d\n", expr->type);
|
||||
printf("expr->lval_type = %d\n", expr->lval_type);
|
||||
if ( expr == NULL ) return 24;
|
||||
if ( expr->type != BASIC_OPTP_NONE ) return 25;
|
||||
if ( expr->lval_type != BASIC_LVAL_CONST_INT ) return 26;
|
||||
if ( expr->lval.i != 10 ) return 27;
|
||||
|
||||
|
||||
/*
|
||||
arrayline = &basic_memory_lines[0];
|
||||
if ( retline != arrayline) return 13;
|
||||
|
||||
36
tests/basic_solver.c
Normal file
36
tests/basic_solver.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "types.h"
|
||||
#include "basic.h"
|
||||
#include "string.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
basic_expr expr;
|
||||
basic_variable result;
|
||||
result.flags = 0;
|
||||
|
||||
expr.type = BASIC_OPTP_ADD;
|
||||
expr.lval_type = BASIC_LVAL_CONST_INT;
|
||||
expr.lval.i = 1;
|
||||
expr.rval_type = BASIC_RVAL_CONST_INT;
|
||||
expr.rval.i = 1;
|
||||
|
||||
basic_solve_expr(&expr, &result);
|
||||
if ( basic_errno != 0 ) return 2;
|
||||
if ( result.flags != (BASIC_VARFLAG_INIT | BASIC_VARFLAG_TINT) ) return 3;
|
||||
if ( result.value.i != 2 ) return 4;
|
||||
|
||||
expr.type = BASIC_OPTP_NONE;
|
||||
expr.lval_type = BASIC_LVAL_CONST_INT;
|
||||
expr.lval.i = 1;
|
||||
expr.rval_type = BASIC_RVAL_NONE;
|
||||
memset(&result, 0x00, sizeof(basic_variable));
|
||||
basic_solve_expr(&expr, &result);
|
||||
if ( basic_errno != 0 ) return 5;
|
||||
if ( result.flags != (BASIC_VARFLAG_INIT | BASIC_VARFLAG_TINT) ) return 6;
|
||||
if ( result.value.i != 1 ) return 7;
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
5
tests/basic_solver.deps
Normal file
5
tests/basic_solver.deps
Normal file
@@ -0,0 +1,5 @@
|
||||
basic
|
||||
stdlib
|
||||
string
|
||||
conio
|
||||
screen
|
||||
@@ -4,11 +4,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
char *_tokenize(char *ptr, char *token);
|
||||
char *_token_get(void);
|
||||
|
||||
#define assert_token_value(str, val, ret_null, ret_neq) \
|
||||
ptr = _tokenize(str, BASIC_TOKENIZER_TOKENS); \
|
||||
value = _token_get(); \
|
||||
value = tokenizer_token(); \
|
||||
if ( ptr == NULL ) return ret_null; \
|
||||
rc = strcmp(value, val); \
|
||||
printf("(%s) => (value) == (val) ? : (%s) == (%s) %d\n", str, value, val, rc); \
|
||||
|
||||
Reference in New Issue
Block a user