2015-01-25 22:05:28 -08:00
|
|
|
#ifndef _BASIC_H_
|
|
|
|
|
#define _BASIC_H_
|
|
|
|
|
|
2024-05-05 06:55:39 -04:00
|
|
|
#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
|
2015-01-25 22:05:28 -08:00
|
|
|
|
|
|
|
|
#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
|
2015-01-26 21:55:55 -08:00
|
|
|
#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
|
2015-01-25 22:05:28 -08:00
|
|
|
|
2024-05-04 22:08:20 -04:00
|
|
|
#define BASIC_TOKENIZER_TOKENS "+-/%*="
|
2015-01-25 22:05:28 -08:00
|
|
|
#define BASIC_TOKENIZER_MAX_LENGTH 512
|
2015-01-26 21:55:55 -08:00
|
|
|
#define BASIC_VARNAME_MAX_LENGTH 16
|
2015-01-25 22:05:28 -08:00
|
|
|
|
2024-05-05 06:55:39 -04:00
|
|
|
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;
|
|
|
|
|
|
2024-05-03 22:26:34 -04:00
|
|
|
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;
|
|
|
|
|
|
2015-01-26 21:55:55 -08:00
|
|
|
struct basic_expr {
|
2015-01-25 22:05:28 -08:00
|
|
|
char type;
|
|
|
|
|
char lval_type;
|
|
|
|
|
char rval_type;
|
|
|
|
|
char pad;
|
2024-05-03 22:26:34 -04:00
|
|
|
basic_value lval;
|
|
|
|
|
basic_value rval;
|
2015-01-25 22:05:28 -08:00
|
|
|
};
|
2024-05-03 22:26:34 -04:00
|
|
|
typedef struct basic_expr basic_expr;
|
2015-01-25 22:05:28 -08:00
|
|
|
|
2015-01-26 21:55:55 -08:00
|
|
|
#define BASIC_VARFLAG_INIT 1
|
|
|
|
|
#define BASIC_VARFLAG_TINT 2
|
|
|
|
|
#define BASIC_VARFLAG_TSTR 4
|
|
|
|
|
|
|
|
|
|
struct basic_variable {
|
|
|
|
|
char *name;
|
|
|
|
|
char flags;
|
2024-05-03 22:26:34 -04:00
|
|
|
basic_value value;
|
2015-01-26 21:55:55 -08:00
|
|
|
};
|
2024-05-03 22:26:34 -04:00
|
|
|
typedef struct basic_variable basic_variable;
|
2015-01-26 21:55:55 -08:00
|
|
|
|
|
|
|
|
#define BASIC_CONST_TRUE 1
|
|
|
|
|
#define BASIC_CONST_FALSE 0
|
|
|
|
|
|
2015-01-25 22:05:28 -08:00
|
|
|
extern int basic_errno;
|
|
|
|
|
|
2024-05-04 22:08:20 -04:00
|
|
|
void basic_repl(basic_program *program);
|
|
|
|
|
basic_expr *basic_parse_expr(char *);
|
2015-01-25 22:05:28 -08:00
|
|
|
|
|
|
|
|
#endif /* _BASIC_H_ */
|