ChipMaster's bwBASIC This also includes history going back to v2.10. *WARN* some binary files might have been corrupted by CRLF.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

353 lines
14 KiB

  1. /***************************************************************
  2. bwb_tbl.c Command, Function, Operator,
  3. and Error-Message Tables
  4. for Bywater BASIC Interpreter
  5. Copyright (c) 1993, Ted A. Campbell
  6. Bywater Software
  7. email: tcamp@delphi.com
  8. Copyright and Permissions Information:
  9. All U.S. and international rights are claimed by the author,
  10. Ted A. Campbell.
  11. This software is released under the terms of the GNU General
  12. Public License (GPL), which is distributed with this software
  13. in the file "COPYING". The GPL specifies the terms under
  14. which users may copy and use the software in this distribution.
  15. A separate license is available for commercial distribution,
  16. for information on which you should contact the author.
  17. ***************************************************************/
  18. /*---------------------------------------------------------------*/
  19. /* NOTE: Modifications marked "JBV" were made by Jon B. Volkoff, */
  20. /* 11/1995 (eidetics@cerf.net). */
  21. /*---------------------------------------------------------------*/
  22. #include <stdio.h>
  23. #include "bwbasic.h"
  24. #include "bwb_mes.h"
  25. int err_line = 0; /* line in which error occurred */
  26. int err_number = 0; /* number of last error */
  27. /***************************************************************
  28. Command Table for Bywater BASIC
  29. ***************************************************************/
  30. struct bwb_command bwb_cmdtable[ COMMANDS ] =
  31. {
  32. #if PERMANENT_DEBUG
  33. { CMD_VARS, bwb_vars },
  34. { CMD_CMDS, bwb_cmds },
  35. { CMD_FNCS, bwb_fncs },
  36. #endif
  37. #if UNIX_CMDS
  38. { CMD_CHDIR, bwb_chdir },
  39. { CMD_MKDIR, bwb_mkdir },
  40. { CMD_RMDIR, bwb_rmdir },
  41. { CMD_KILL, bwb_kill },
  42. { CMD_ENVIRON, bwb_environ },
  43. #endif
  44. #if INTERACTIVE
  45. { CMD_LIST, bwb_list },
  46. { CMD_LOAD, bwb_load },
  47. { CMD_RUN, bwb_run },
  48. { CMD_SAVE, bwb_save },
  49. { CMD_DELETE, bwb_delete },
  50. { CMD_NEW, bwb_new },
  51. { CMD_QUIT, bwb_system },
  52. { CMD_SYSTEM, bwb_system },
  53. #endif
  54. #if MS_CMDS
  55. { CMD_DEFDBL, bwb_ddbl },
  56. { CMD_DEFINT, bwb_dint },
  57. { CMD_DEFSNG, bwb_dsng },
  58. { CMD_DEFSTR, bwb_dstr },
  59. { CMD_MID, bwb_mid }, /* Added this extension (JBV) */
  60. #if IMP_CMDCLS
  61. { CMD_CLS, bwb_cls },
  62. #endif
  63. #if IMP_CMDCOLOR
  64. { CMD_COLOR, bwb_color },
  65. #endif
  66. #if IMP_CMDLOC
  67. { CMD_LOCATE, bwb_locate },
  68. #endif
  69. #endif
  70. #if STRUCT_CMDS
  71. { CMD_CALL, bwb_call },
  72. { CMD_SUB, bwb_sub },
  73. { CMD_FUNCTION, bwb_function },
  74. { CMD_LABEL, bwb_null },
  75. { CMD_ELSE, bwb_else },
  76. { CMD_ELSEIF, bwb_elseif },
  77. { CMD_SELECT, bwb_select },
  78. { CMD_CASE, bwb_case },
  79. { CMD_LOOP, bwb_loop },
  80. { CMD_EXIT, bwb_exit },
  81. #endif
  82. #if COMMON_CMDS
  83. { CMD_MERGE, bwb_merge },
  84. { CMD_CHAIN, bwb_chain },
  85. { CMD_COMMON, bwb_common },
  86. { CMD_ERROR, bwb_lerror },
  87. { CMD_WIDTH, bwb_width },
  88. { CMD_TRON, bwb_tron },
  89. { CMD_TROFF, bwb_troff },
  90. { CMD_FILES, bwb_files },
  91. { CMD_EDIT, bwb_edit },
  92. { CMD_ERASE, bwb_erase },
  93. { CMD_SWAP, bwb_swap },
  94. { CMD_NAME, bwb_name },
  95. { CMD_CLEAR, bwb_clear },
  96. { CMD_WHILE, bwb_while },
  97. { CMD_WEND, bwb_wend },
  98. { CMD_WRITE, bwb_write },
  99. { CMD_OPEN, bwb_open },
  100. { CMD_CLOSE, bwb_close },
  101. { CMD_GET, bwb_get },
  102. { CMD_PUT, bwb_put },
  103. { CMD_LSET, bwb_lset },
  104. { CMD_RSET, bwb_rset },
  105. { CMD_FIELD, bwb_field },
  106. { CMD_LINE, bwb_line },
  107. { CMD_RENUM, bwb_renum }, /* Added this extension (JBV) */
  108. #endif
  109. /* The remainder are the core functions defined for ANSI Minimal BASIC */
  110. { CMD_DATA, bwb_data },
  111. { CMD_DEF, bwb_def },
  112. { CMD_DIM, bwb_dim },
  113. { CMD_END, bwb_xend },
  114. { CMD_FOR, bwb_for },
  115. { CMD_DO, bwb_do }, /* not really core but needed in two different places */
  116. { CMD_GO, bwb_go },
  117. { CMD_GOSUB, bwb_gosub },
  118. { CMD_GOTO, bwb_goto },
  119. { CMD_IF, bwb_if },
  120. { CMD_INPUT, bwb_input },
  121. { CMD_LET, bwb_let },
  122. { CMD_NEXT, bwb_next },
  123. { CMD_ON, bwb_on },
  124. { CMD_OPTION, bwb_option },
  125. { CMD_PRINT, bwb_print },
  126. { CMD_RANDOMIZE, bwb_randomize },
  127. { CMD_READ, bwb_read },
  128. { CMD_REM, bwb_rem },
  129. { CMD_RESTORE, bwb_restore },
  130. { CMD_RETURN, bwb_return },
  131. { CMD_STOP, bwb_stop }
  132. };
  133. /***************************************************************
  134. Predefined Function Table for Bywater BASIC
  135. ***************************************************************/
  136. struct bwb_function bwb_prefuncs[ FUNCTIONS ] =
  137. {
  138. #if INTENSIVE_DEBUG
  139. { "TEST", NUMBER, 2, fnc_test, (struct bwb_function *) NULL, 0 },
  140. #endif
  141. #if MS_FUNCS /* Functions unique to Microsoft GWBASIC (tm) */
  142. { "ASC", NUMBER, 1, fnc_asc, (struct bwb_function *) NULL, 0 },
  143. { "MKD$", STRING, 1, fnc_mkd, (struct bwb_function *) NULL, 0 },
  144. { "MKI$", STRING, 1, fnc_mki, (struct bwb_function *) NULL, 0 },
  145. { "MKS$", STRING, 1, fnc_mks, (struct bwb_function *) NULL, 0 },
  146. { "CVD", NUMBER, 1, fnc_cvd, (struct bwb_function *) NULL, 0 },
  147. { "CVS", NUMBER, 1, fnc_cvs, (struct bwb_function *) NULL, 0 },
  148. { "CVI", NUMBER, 1, fnc_cvi, (struct bwb_function *) NULL, 0 },
  149. { "CINT", NUMBER, 1, fnc_cint, (struct bwb_function *) NULL, 0 },
  150. { "CSNG", NUMBER, 1, fnc_csng, (struct bwb_function *) NULL, 0 },
  151. { "ENVIRON$",STRING, 1, fnc_environ, (struct bwb_function *) NULL, 0 },
  152. { "ERR", NUMBER, 0, fnc_err, (struct bwb_function *) NULL, 0 },
  153. { "ERL", NUMBER, 0, fnc_erl, (struct bwb_function *) NULL, 0 },
  154. { "LOC", NUMBER, 1, fnc_loc, (struct bwb_function *) NULL, 0 },
  155. { "LOF", NUMBER, 1, fnc_lof, (struct bwb_function *) NULL, 0 },
  156. { "EOF", NUMBER, 1, fnc_eof, (struct bwb_function *) NULL, 0 },
  157. { "INSTR", NUMBER, 1, fnc_instr, (struct bwb_function *) NULL, 0 },
  158. { "SPC", STRING, 1, fnc_spc, (struct bwb_function *) NULL, 0 },
  159. { "SPACE$", STRING, 1, fnc_space, (struct bwb_function *) NULL, 0 },
  160. { "STRING$", STRING, 1, fnc_string, (struct bwb_function *) NULL, 0 },
  161. { "MID$", STRING, 3, fnc_mid, (struct bwb_function *) NULL, 0 },
  162. { "LEFT$", STRING, 2, fnc_left, (struct bwb_function *) NULL, 0 },
  163. { "RIGHT$", STRING, 2, fnc_right, (struct bwb_function *) NULL, 0 },
  164. { "TIMER", NUMBER, 0, fnc_timer, (struct bwb_function *) NULL, 0 },
  165. { "HEX$", STRING, 1, fnc_hex, (struct bwb_function *) NULL, 0 },
  166. { "OCT$", STRING, 1, fnc_oct, (struct bwb_function *) NULL, 0 },
  167. #if IMP_FNCINKEY == 1
  168. { "INKEY$", STRING, 1, fnc_inkey, (struct bwb_function *) NULL, 0 },
  169. #endif
  170. #endif
  171. #if COMMON_FUNCS /* Functions common to GWBASIC and ANSI Full BASIC */
  172. { "CHR$", NUMBER, 0, fnc_chr, (struct bwb_function *) NULL, 0 },
  173. { "LEN", NUMBER, 1, fnc_len, (struct bwb_function *) NULL, 0 },
  174. { "POS", NUMBER, 0, fnc_pos, (struct bwb_function *) NULL, 0 },
  175. { "VAL", NUMBER, 1, fnc_val, (struct bwb_function *) NULL, 0 },
  176. { "STR$", STRING, 1, fnc_str, (struct bwb_function *) NULL, 0 },
  177. { "DATE$", STRING, 0, fnc_date, (struct bwb_function *) NULL, 0 },
  178. { "TIME$", STRING, 0, fnc_time, (struct bwb_function *) NULL, 0 },
  179. #endif
  180. #if ANSI_FUNCS /* Functions required for ANSI Full BASIC */
  181. { "COSH", NUMBER, 1, fnc_cosh, (struct bwb_function *) NULL, 0},
  182. { "SINH", NUMBER, 1, fnc_sinh, (struct bwb_function *) NULL, 0},
  183. { "TANH", NUMBER, 1, fnc_tanh, (struct bwb_function *) NULL, 0},
  184. { "LOG10", NUMBER, 1, fnc_log10, (struct bwb_function *) NULL, 0},
  185. { "LOG2", NUMBER, 1, fnc_log2, (struct bwb_function *) NULL, 0},
  186. { "ACOS", NUMBER, 1, fnc_acos, (struct bwb_function *) NULL, 0},
  187. { "ASIN", NUMBER, 1, fnc_asin, (struct bwb_function *) NULL, 0},
  188. { "COT", NUMBER, 1, fnc_cotan, (struct bwb_function *) NULL, 0},
  189. { "CSC", NUMBER, 1, fnc_cosecant, (struct bwb_function *) NULL, 0},
  190. { "SEC", NUMBER, 1, fnc_secant, (struct bwb_function *) NULL, 0},
  191. #endif
  192. /* The remainder are core functions defined for ANSI Minimal BASIC */
  193. #if COMPRESS_FUNCS
  194. { "ABS", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_ABS },
  195. { "ATN", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_ATN },
  196. { "COS", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_COS },
  197. { "EXP", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_EXP },
  198. { "INT", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_INT },
  199. { "LOG", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_LOG },
  200. { "RND", NUMBER, 0, fnc_core, (struct bwb_function *) NULL, F_RND },
  201. { "SGN", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_SGN },
  202. { "SIN", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_SIN },
  203. { "SQR", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_SQR },
  204. { "TAN", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_TAN },
  205. #else
  206. { "ABS", NUMBER, 1, fnc_abs, (struct bwb_function *) NULL, 0 },
  207. { "ATN", NUMBER, 1, fnc_atn, (struct bwb_function *) NULL, 0 },
  208. { "COS", NUMBER, 1, fnc_cos, (struct bwb_function *) NULL, 0 },
  209. { "EXP", NUMBER, 1, fnc_exp, (struct bwb_function *) NULL, 0 },
  210. { "INT", NUMBER, 1, fnc_int, (struct bwb_function *) NULL, 0 },
  211. { "LOG", NUMBER, 1, fnc_log, (struct bwb_function *) NULL, 0 },
  212. { "RND", NUMBER, 0, fnc_rnd, (struct bwb_function *) NULL, 0 },
  213. { "SGN", NUMBER, 1, fnc_sgn, (struct bwb_function *) NULL, 0 },
  214. { "SIN", NUMBER, 1, fnc_sin, (struct bwb_function *) NULL, 0 },
  215. { "SQR", NUMBER, 1, fnc_sqr, (struct bwb_function *) NULL, 0 },
  216. { "TAN", NUMBER, 1, fnc_tan, (struct bwb_function *) NULL, 0 },
  217. #endif
  218. { "TAB", STRING, 1, fnc_tab, (struct bwb_function *) NULL, 0 }
  219. };
  220. /***************************************************************
  221. Operator Table for Bywater BASIC
  222. ***************************************************************/
  223. struct bwb_op exp_ops[ N_OPERATORS ] =
  224. {
  225. { "NOT", OP_NOT, 2 }, /* multiple-character operators */
  226. { "AND", OP_AND, 13 }, /* should be tested first because */
  227. { "OR", OP_OR, 14 }, /* e.g. a ">=" would be matched */
  228. { "XOR", OP_XOR, 15 }, /* as "=" if the single-character */
  229. { "IMP", OP_IMPLIES, 16 }, /* operator came first */
  230. { "EQV", OP_EQUIV, 17 },
  231. { "MOD", OP_MODULUS, 5 },
  232. { "<>", OP_NOTEQUAL, 8 },
  233. { "<=", OP_LTEQ, 11 },
  234. { "=<", OP_LTEQ, 11 }, /* allow either form */
  235. { ">=", OP_GTEQ, 12 },
  236. { "=>", OP_GTEQ, 12 }, /* allow either form */
  237. { "<", OP_LESSTHAN, 9 },
  238. { ">", OP_GREATERTHAN, 10 },
  239. { "^", OP_EXPONENT, 0 },
  240. { "*", OP_MULTIPLY, 3 },
  241. { "/", OP_DIVIDE, 3 },
  242. { "\\", OP_INTDIVISION, 4 },
  243. { "+", OP_ADD, 6 },
  244. { "-", OP_SUBTRACT, 6 },
  245. { "=", OP_EQUALS, 7 },
  246. { "=", OP_ASSIGN, 18 }, /* don't worry: OP_EQUALS will be converted to OP_ASSIGN if necessary */
  247. { ";", OP_STRJOIN, 19 },
  248. { ",", OP_STRTAB, 20 },
  249. { "-", OP_NEGATION, 1 } /* Right below exponentiation (JBV) */
  250. };
  251. /* Error messages used more than once */
  252. char err_openfile[] = ERR_OPENFILE;
  253. char err_getmem[] = ERR_GETMEM;
  254. char err_noln[] = ERR_NOLN;
  255. char err_nofn[] = ERR_NOFN;
  256. char err_lnnotfound[] = ERR_LNNOTFOUND;
  257. char err_incomplete[] = ERR_INCOMPLETE;
  258. char err_valoorange[] = ERR_VALOORANGE;
  259. char err_syntax[] = ERR_SYNTAX;
  260. char err_devnum[] = ERR_DEVNUM;
  261. char err_dev[] = ERR_DEV;
  262. char err_opsys[] = ERR_OPSYS;
  263. char err_argstr[] = ERR_ARGSTR;
  264. char err_defchar[] = ERR_DEFCHAR;
  265. char err_mismatch[] = ERR_MISMATCH;
  266. char err_dimnotarray[] =ERR_DIMNOTARRAY;
  267. char err_retnogosub[] = ERR_RETNOGOSUB;
  268. char err_od[] = ERR_OD;
  269. char err_overflow[] = ERR_OVERFLOW;
  270. char err_nf[] = ERR_NF;
  271. char err_uf[] = ERR_UF;
  272. char err_dbz[] = ERR_DBZ;
  273. char err_redim[] = ERR_REDIM;
  274. char err_obdim[] = ERR_OBDIM;
  275. char err_uc[] = ERR_UC;
  276. char err_noprogfile[] = ERR_NOPROGFILE;
  277. /***************************************************************
  278. Error Message Table for Bywater BASIC
  279. ***************************************************************/
  280. char *err_table[ N_ERRORS ] =
  281. {
  282. err_openfile,
  283. err_getmem,
  284. err_noln,
  285. err_nofn,
  286. err_lnnotfound,
  287. err_incomplete,
  288. err_valoorange,
  289. err_syntax,
  290. err_devnum,
  291. err_dev,
  292. err_opsys,
  293. err_argstr,
  294. err_defchar,
  295. err_mismatch,
  296. err_dimnotarray,
  297. err_od,
  298. err_overflow,
  299. err_nf,
  300. err_uf,
  301. err_dbz,
  302. err_redim,
  303. err_obdim,
  304. err_uc,
  305. err_noprogfile
  306. };