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.
 
 
 
 
 
 

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