2024-05-04 22:08:20 -04:00
|
|
|
#include "types.h"
|
|
|
|
|
#include "basic.h"
|
2024-05-06 14:51:04 -04:00
|
|
|
#include "string.h"
|
|
|
|
|
#include <stdio.h>
|
2024-05-04 22:08:20 -04:00
|
|
|
|
2024-05-06 14:51:04 -04:00
|
|
|
/* extern basic_line basic_memory_lines[BASIC_MAX_LINES]; */
|
2024-05-04 22:08:20 -04:00
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
|
|
|
|
struct basic_expr *expr;
|
2024-05-06 15:12:12 -04:00
|
|
|
char *line;
|
2024-05-06 14:51:04 -04:00
|
|
|
/*struct basic_line *retline;
|
|
|
|
|
struct basic_line *arrayline;*/
|
|
|
|
|
|
2024-05-05 06:55:39 -04:00
|
|
|
/* Store a line */
|
2024-05-06 14:51:04 -04:00
|
|
|
/* expr = basic_parse_expr("10 =1 + 1");
|
2024-05-05 06:55:39 -04:00
|
|
|
if ( expr == NULL ) return 1;
|
2024-05-06 15:12:12 -04:00
|
|
|
if ( expr->lval_type != BASIC_LVAL_CONST_INT ) return 2;
|
2024-05-05 06:55:39 -04:00
|
|
|
if ( expr->rval_type != BASIC_RVAL_PTR ) return 3;
|
|
|
|
|
if ( expr->lval.i != 10 ) return 4;
|
|
|
|
|
if ( expr->rval.ptr == NULL ) return 5;
|
|
|
|
|
if ( expr->type != BASIC_OPTP_STOR ) return 6;
|
2024-05-06 14:51:04 -04:00
|
|
|
*/
|
2024-05-05 06:55:39 -04:00
|
|
|
/* Parse the stored line */
|
2024-05-06 14:51:04 -04:00
|
|
|
/* retline = (basic_line *)expr->rval.ptr;
|
|
|
|
|
expr = basic_parse_expr(retline->content);*/
|
|
|
|
|
expr = basic_parse_expr("1 + 1");
|
|
|
|
|
if ( expr == NULL ) return 7;
|
2024-05-06 15:12:12 -04:00
|
|
|
if ( expr->lval_type != BASIC_LVAL_CONST_INT ) return 8;
|
|
|
|
|
if ( expr->rval_type != BASIC_RVAL_CONST_INT ) return 9;
|
2024-05-06 14:51:04 -04:00
|
|
|
if ( expr->lval.i != 1 ) return 10;
|
|
|
|
|
if ( expr->rval.i != 1 ) return 11;
|
|
|
|
|
if ( expr->type != BASIC_OPTP_ADD ) return 12;
|
|
|
|
|
|
2024-05-06 15:12:12 -04:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
2024-05-06 14:51:04 -04:00
|
|
|
/*
|
|
|
|
|
arrayline = &basic_memory_lines[0];
|
|
|
|
|
if ( retline != arrayline) return 13;
|
|
|
|
|
printf("Line 10 in memory is %d : %s (%p)\n", arrayline->lineno, (char *)&arrayline->content, (void *)arrayline->nextline);
|
|
|
|
|
if ( arrayline->lineno != 10 ) return 14;
|
|
|
|
|
if ( strcmp((char *)&arrayline->content, "=1 + 1") != 0) return 15;
|
|
|
|
|
if ( arrayline->nextline != NULL ) return 16;
|
|
|
|
|
*/
|
2024-05-04 22:08:20 -04:00
|
|
|
return 0;
|
|
|
|
|
}
|