#ifndef _BASIC_H_ #define _BASIC_H_ #define BASIC_MAX_LINES 1000 #define BASIC_MAX_LINE_LENGTH 256 #define BASIC_OPTP_ADD 1 /* Add */ #define BASIC_OPTP_SUB 2 /* Subtract */ #define BASIC_OPTP_MUL 3 /* Multiply */ #define BASIC_OPTP_DIV 4 /* Divide */ #define BASIC_OPTP_MOD 5 /* Modulus */ #define BASIC_OPTP_EQL 6 /* Equality test */ #define BASIC_OPTP_ASN 7 /* Assignment */ #define BASIC_OPTP_STOR 8 /* Store line for later */ #define BASIC_LVAL_EXPR 0 #define BASIC_LVAL_VAR 1 #define BASIC_LVAL_CONST 2 #define BASIC_RVAL_EXPR 3 #define BASIC_RVAL_VAR 4 #define BASIC_RVAL_CONST 5 #define BASIC_RVAL_PTR 6 /* Only used internally */ #define BASIC_PARSE_FOUND_LVAL 1 #define BASIC_PARSE_FOUND_RVAL 2 #define BASIC_PARSE_FIRSTTOKEN 4 #define BASIC_ERR_SYNTAX_MULTIPLE_LVALUES 1 #define BASIC_ERR_SYNTAX_TOKEN_LENGTH 2 #define BASIC_ERR_SYNTAX_GENERAL 3 #define BASIC_ERR_SYNTAX_MULTIPLE_RVALUES 4 #define BASIC_ERR_INVALID_ARGUMENTS 5 #define BASIC_ERR_INTERNAL_NULLPOINTER 6 #define BASIC_ERR_INTERNAL_MEMORY 7 #define BASIC_ERR_INTERNAL_UNDEFINED_BEHAVIOR 8 #define BASIC_ERR_INTERNAL_UNIMPLEMENTED 9 #define BASIC_ERR_MATH_DBZ 10 #define BASIC_TOKENIZER_TOKENS "+-/%*=" #define BASIC_TOKENIZER_MAX_LENGTH 512 #define BASIC_VARNAME_MAX_LENGTH 16 struct basic_line { int lineno; char content[BASIC_MAX_LINE_LENGTH]; struct basic_line *nextline; }; typedef struct basic_line basic_line; struct basic_program { char name[128]; basic_line *first; }; typedef struct basic_program basic_program; union basic_value { char c; int i; unsigned int uint; /* we don't handle floats yet. need to implement Fcomp, fpushf, fpushd. * float f; */ char *str; void *ptr; }; typedef union basic_value basic_value; struct basic_expr { char type; char lval_type; char rval_type; char pad; basic_value lval; basic_value rval; }; typedef struct basic_expr basic_expr; #define BASIC_VARFLAG_INIT 1 #define BASIC_VARFLAG_TINT 2 #define BASIC_VARFLAG_TSTR 4 struct basic_variable { char *name; char flags; basic_value value; }; typedef struct basic_variable basic_variable; #define BASIC_CONST_TRUE 1 #define BASIC_CONST_FALSE 0 extern int basic_errno; void basic_repl(basic_program *program); basic_expr *basic_parse_expr(char *); #endif /* _BASIC_H_ */