⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bwbasic.h

📁 这是一个简易的basic语言解释器, 可供我们学习和改进.
💻 H
📖 第 1 页 / 共 4 页
字号:
#define CMDS_MS         5+IMP_CMDCLS+IMP_CMDLOC+IMP_CMDCOLOR#else#define CMDS_MS		0#endif#if DEBUG#define CMDS_DEBUG      3               /* number of debugging cmds */#else#define CMDS_DEBUG      0               /* no debugging cmds */#endif#define COMMANDS        (CMDS_CORE+CMDS_DEBUG+CMDS_DIR+CMDS_COMMON+CMDS_INT+CMDS_MS+CMDS_STC)/* define number of functions */#define FUNCS_BASE      12		/* number of basic functions */#ifdef INTENSIVE_DEBUG#define FUNCS_DEBUG	1		/* number of debugging functions */#else#define FUNCS_DEBUG	0		/* number of debugging functions */#endif#if MS_FUNCS#define FUNCS_MS        (25+IMP_FNCINKEY)#else#define FUNCS_MS	0#endif#if COMMON_FUNCS#define FUNCS_COMMON    7#else#define FUNCS_COMMON	0#endif#if ANSI_FUNCS#define FUNCS_ANSI	0#else#define FUNCS_ANSI	0#endif#define FUNCTIONS	(FUNCS_BASE+FUNCS_DEBUG+FUNCS_MS+FUNCS_COMMON+FUNCS_ANSI)/* Check for inconsistencies */#if MULTISEG_LINES & STRUCT_CMDS/* ERROR:  MULTISEG_LINES and STRUCT_CMDS cannot be defined together! */#endif/***************************************************************	bwbasic.h:	Part I-G: Define User Defaults			Defining your default editor and files commands			is a good idea. You must supply the file name			for the editor to use.  These defaults can be			changed from inside the program or in your profile			program by setting the appropriate variables			shown below.***************************************************************/#define DEF_EDITOR      "vi"            /* default editor */#define DEF_FILES       "ls -Fx"         /* default "files" command */#define DEF_COLORS      256             /* default # of colors */#define DEFVNAME_EDITOR "BWB.EDITOR$"   /* default variable name for EDITOR */#define DEFVNAME_PROMPT "BWB.PROMPT$"   /* default variable name for PROMPT */#define DEFVNAME_FILES  "BWB.FILES$"    /* default variable name for FILES */#define DEFVNAME_COLORS "BWB.COLORS"    /* default variable name for COLORS */#define DEFVNAME_IMPL   "BWB.IMPLEMENTATION$" /* default variable name for IMPLEMENTATION */#define ERRFILE         "err.out"       /* Filename for redirected error messages */#define PROFILENAME	"profile.bas"	/* Filename for profile execution */#define	TASKS		4		/* number of tasks available */#define MAXARGSIZE      128             /* maximum size of argument */#define MAXREADLINESIZE 256             /* size of read_line buffer */#define MAXCMDNAMESIZE  64              /* maximum size for command name */#define MAXLINENO       32766           /* maximum line number */#define MAXVARNAMESIZE  40              /* maximum size for variable name */#define MAXFILENAMESIZE 40              /* maximum size for file name */#define MAXSTRINGSIZE   255             /* maximum string length */#define EXECLEVELS      64              /* EXEC stack levels */#define MAX_GOLINES     12              /* Maximum # of lines for ON...GOTO statements */#define MAX_FARGS       6               /* maximum # arguments to function */#define MAX_DIMS	64		/* maximum # of dimensions */#define ESTACKSIZE      64              /* elements in expression stack */#define XTXTSTACKSIZE   16              /* elements in eXecute TeXT stack */#define N_OPERATORS     25              /* number of operators defined */#define N_ERRORS	25		/* number of errors defined */#define MAX_PRECEDENCE  20              /* highest (last) level of precedence */#define MININTSIZE      -32767          /* minimum integer size */#define MAXINTSIZE       32767          /* maximum integer size */#define DEF_SUBSCRIPT   11              /* default subscript */#define DEF_DEVICES     16              /* default number of devices available */#define DEF_WIDTH	128		/* default width for devices */#define PRN_TAB		0x02		/* send TAB followed by col number to output device */#define COMPRESS_FUNCS  TRUE/* Derivative definitions */#if MULTISEG_LINES#define MARK_LINES	FALSE#else#define MARK_LINES	TRUE#endif#if PARACT#define CURTASK		bwb_tasks[ bwb_curtask ]->#define LOCALTASK	bwb_tasks[ task ]->#else#define CURTASK#define LOCALTASK#endif#if DEBUG#define PERMANENT_DEBUG TRUE#else#define PERMANENT_DEBUG FALSE#endif#if HAVE_STDLIB#elseextern char *calloc();#ifndef NULL#define NULL	0L#endif#endif/* typedef for BASIC number */#if NUMBER_DOUBLEtypedef double bnumber;#elsetypedef float bnumber;#endif/* define variable types based on last character */#define STRING          '$'/* define mathematical operations */#define MULTIPLY        '*'#define DIVIDE          '/'#define ADD             '+'#define SUBTRACT        '-'#define ARGUMENT        'A'/* Operations defined */#define OP_ERROR        -255		/* operation error (break out) */#define OP_NULL         0               /* null: operation not defined yet */#define NUMBER          1               /* number held as internal variable in uvar */#define CONST_STRING    2               /* string constant */#define CONST_NUMERICAL 3               /* numerical constant */#define FUNCTION        4               /* function header */#define VARIABLE        5               /* external variable pointed to by xvar */#define PARENTHESIS     6               /* begin parenthetical expression */#define OP_ADD          7               /* addition sign '+' */#define OP_SUBTRACT     8               /* subtraction sign '-' */#define OP_MULTIPLY     9               /* multiplication sign '*' */#define OP_DIVIDE       10              /* division sign '/' */#define OP_MODULUS      11              /* modulus "MOD" */#define OP_EXPONENT     12              /* exponentiation '^' */#define OP_INTDIVISION  13              /* integer division sign '\' */#define OP_NEGATION     14              /* negation '-' ??? */#define OP_STRJOIN      15              /* string join ';' */#define OP_STRTAB       16              /* string tab ',' */#define OP_EQUALS       17              /* either logical equal operator */#define OP_ASSIGN       18              /* assignment operator */#define OP_NOTEQUAL     20              /* inequality */#define OP_LESSTHAN     21              /* less than */#define OP_GREATERTHAN  22              /* greater than */#define OP_LTEQ         23              /* less than or equal to */#define OP_GTEQ         24              /* greater than or equal to */#define OP_NOT          25              /* negation */#define OP_AND          26              /* conjunction */#define OP_OR           27              /* disjunction */#define OP_XOR          28              /* exclusive or */#define OP_IMPLIES      29              /* implication */#define OP_EQUIV        30              /* equivalence */#define OP_TERMINATE    31              /* terminate expression parsing */#define OP_USERFNC	32		/* user-defined function *//* Device input/output modes */#define DEVMODE_AVAILABLE  -1#define DEVMODE_CLOSED     0#define DEVMODE_OUTPUT     1#define DEVMODE_INPUT      2#define DEVMODE_APPEND     3#define DEVMODE_RANDOM     4/* codes for EXEC stack and for function-sub-label lookup table */#define EXEC_NORM	0#define	EXEC_GOSUB	1#define	EXEC_WHILE	2#define EXEC_FOR        3#define EXEC_FUNCTION	4#define EXEC_CALLSUB	5#define EXEC_IFTRUE	6#define EXEC_IFFALSE	7#define EXEC_MAIN	8#define EXEC_SELTRUE	9#define EXEC_SELFALSE	10#define EXEC_LABEL      11#define EXEC_DO         12#define EXEC_ON         13/***************************************************************	bwbasic.h	Part II: Structures***************************************************************//* Typdef structure for strings under Bywater BASIC */typedef struct bstr   {   unsigned char length;		/* length of string */   char *sbuffer;			/* pointer to string buffer */   int rab;				/* is it a random-access buffer? */#if TEST_BSTRING   char name[ MAXVARNAMESIZE + 1 ];	/* name for test purposes */#endif   } bstring;/* Structure used for all variables under Bywater BASIC */struct bwb_variable   {   char name[ MAXVARNAMESIZE + 1 ];	/* name */   int type;                            /* type, i.e., STRING or NUMBER */#if OLDWAY   void *array;				/* pointer to array memory */#endif   bnumber *memnum;			/* memory for number */   bstring *memstr;			/* memory for string */   size_t array_units;			/* total number of units of memory */   int  *array_sizes;			/* pointer to array of <dimensions>                                           integers, with sizes of each                                           dimension */   int *array_pos;                      /* current position in array */   int dimensions;                      /* number of dimensions,                                           0 = not an array */   struct bwb_variable *next;           /* next variable in chain */   int common;				/* should this variable be common to chained programs? */   int preset;				/* preset variable: CLEAR should not alter */   };/* Structure to represent program lines under Bywater BASIC */struct bwb_line   {   struct bwb_line *next;               /* pointer to next line in chain */   int number;                          /* line number */   char xnum;				/* is there actually a line number? */   char *buffer;			/* buffer to hold the line */   int position;                        /* current position in line */   int lnpos;                           /* line number position in buffer */   int lnum;                            /* line number read from buffer */   int cmdpos;                          /* command position in buffer */   int cmdnum;                          /* number of command in command table                                           read from buffer */   int startpos;                        /* start of rest of line read from buffer */   int marked;                          /* has line been checked yet? */   };/* Structure used for all predefined functions under Bywater BASIC */struct bwb_function   {   char name[ MAXVARNAMESIZE + 1 ];     /* name */   int type;                            /* type, i.e., STRING or NUMBER */   int arguments;                       /* number of args passed */#if ANSI_C   struct bwb_variable * (*vector) ( int argc, struct bwb_variable *argv, int unique_id );  /* vector to function to call */#else   struct bwb_variable * (*vector) ();  /* vector to function to call */#endif   struct bwb_function *next;           /* next function in chain */   int id;                              /* id to identify multiple functions */   };/* Structure to represent all command statements under Bywater BASIC */struct bwb_command   {   char name[ MAXCMDNAMESIZE + 1 ];#if ANSI_C   struct bwb_line * (*vector) (struct bwb_line *);#else   struct bwb_line * (*vector) ();#endif   };/* Structure to define device stack for Bywater BASIC */struct dev_element   {   int mode;                            /* DEVMODE_ item */   int width;				/* width for output control */   int col;				/* current column */   int reclen;                          /* record length for random access */   int next_record;			/* next record to read/write */   int loc;				/* location in file */   int lof;				/* length of file in bytes (JBV) */   char filename[ MAXFILENAMESIZE + 1 ];/* filename */   FILE *cfp;                           /* C file pointer for this device */   char *buffer;			/* pointer to character buffer for random access */   };/* Structure to define expression stack elements under Bywater BASIC */struct exp_ese   {   int operation;                       /* operation at this level */   char type;				/* type of operation at this level:   					   STRING or NUMBER */   bstring sval;			/* string */   bnumber nval;			/* number */   char string[ MAXSTRINGSIZE + 1 ]; 	/* string for writing */   struct bwb_variable *xvar;           /* pointer to external variable */   struct bwb_function *function;       /* pointer to function structure */   int array_pos[ MAX_DIMS ];		/* array for variable positions */   int pos_adv;                         /* position advanced in string */   int rec_pos;                         /* position marker for recursive calls */   };/* structure for FUNCTION-SUB loopup table element */struct fslte   {   char *name;   struct bwb_line *line;   int code;   int startpos;			/* starting position in line */   struct fslte *next;   struct bwb_variable *local_variable;   };/* Structure to define EXEC stack elements */struct exse   {   struct bwb_line *line;		/* line for execution */   int code;				/* code to note special operations */   int position;			/* position in line for restore */   struct bwb_variable *local_variable;	/* local variable chain and current FOR counter */   struct bwb_variable *calling_variable[ MAX_FARGS ];   int n_cvs;				/* number of calling variables */   int for_step;			/* STEP value for FOR */   int for_target;			/* target value for FOR */   struct bwb_line *while_line;		/* return line for current WHILE */   struct bwb_line *wend_line;          /* breakout line for current WHILE (or FOR-NEXT) */   struct exp_ese expression;		/* expression for evaluation by SELECT CASE */#if MULTISEG_LINES   struct bwb_line *for_line;           /* top line for FOR-NEXT loop, multisegmented */   int for_position;                    /* position in top line for FOR-NEXT loop, multisegmented */#endif   };struct xtxtsl   {   int  position;   struct bwb_line l;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -