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.
 
 
 
 
 
 

343 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. #endif
  182. /* The remainder are core functions defined for ANSI Minimal BASIC */
  183. #if COMPRESS_FUNCS
  184. { "ABS", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_ABS },
  185. { "ATN", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_ATN },
  186. { "COS", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_COS },
  187. { "EXP", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_EXP },
  188. { "INT", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_INT },
  189. { "LOG", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_LOG },
  190. { "RND", NUMBER, 0, fnc_core, (struct bwb_function *) NULL, F_RND },
  191. { "SGN", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_SGN },
  192. { "SIN", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_SIN },
  193. { "SQR", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_SQR },
  194. { "TAN", NUMBER, 1, fnc_core, (struct bwb_function *) NULL, F_TAN },
  195. #else
  196. { "ABS", NUMBER, 1, fnc_abs, (struct bwb_function *) NULL, 0 },
  197. { "ATN", NUMBER, 1, fnc_atn, (struct bwb_function *) NULL, 0 },
  198. { "COS", NUMBER, 1, fnc_cos, (struct bwb_function *) NULL, 0 },
  199. { "EXP", NUMBER, 1, fnc_exp, (struct bwb_function *) NULL, 0 },
  200. { "INT", NUMBER, 1, fnc_int, (struct bwb_function *) NULL, 0 },
  201. { "LOG", NUMBER, 1, fnc_log, (struct bwb_function *) NULL, 0 },
  202. { "RND", NUMBER, 0, fnc_rnd, (struct bwb_function *) NULL, 0 },
  203. { "SGN", NUMBER, 1, fnc_sgn, (struct bwb_function *) NULL, 0 },
  204. { "SIN", NUMBER, 1, fnc_sin, (struct bwb_function *) NULL, 0 },
  205. { "SQR", NUMBER, 1, fnc_sqr, (struct bwb_function *) NULL, 0 },
  206. { "TAN", NUMBER, 1, fnc_tan, (struct bwb_function *) NULL, 0 },
  207. #endif
  208. { "TAB", STRING, 1, fnc_tab, (struct bwb_function *) NULL, 0 }
  209. };
  210. /***************************************************************
  211. Operator Table for Bywater BASIC
  212. ***************************************************************/
  213. struct bwb_op exp_ops[ N_OPERATORS ] =
  214. {
  215. { "NOT", OP_NOT, 2 }, /* multiple-character operators */
  216. { "AND", OP_AND, 13 }, /* should be tested first because */
  217. { "OR", OP_OR, 14 }, /* e.g. a ">=" would be matched */
  218. { "XOR", OP_XOR, 15 }, /* as "=" if the single-character */
  219. { "IMP", OP_IMPLIES, 16 }, /* operator came first */
  220. { "EQV", OP_EQUIV, 17 },
  221. { "MOD", OP_MODULUS, 5 },
  222. { "<>", OP_NOTEQUAL, 8 },
  223. { "<=", OP_LTEQ, 11 },
  224. { "=<", OP_LTEQ, 11 }, /* allow either form */
  225. { ">=", OP_GTEQ, 12 },
  226. { "=>", OP_GTEQ, 12 }, /* allow either form */
  227. { "<", OP_LESSTHAN, 9 },
  228. { ">", OP_GREATERTHAN, 10 },
  229. { "^", OP_EXPONENT, 0 },
  230. { "*", OP_MULTIPLY, 3 },
  231. { "/", OP_DIVIDE, 3 },
  232. { "\\", OP_INTDIVISION, 4 },
  233. { "+", OP_ADD, 6 },
  234. { "-", OP_SUBTRACT, 6 },
  235. { "=", OP_EQUALS, 7 },
  236. { "=", OP_ASSIGN, 18 }, /* don't worry: OP_EQUALS will be converted to OP_ASSIGN if necessary */
  237. { ";", OP_STRJOIN, 19 },
  238. { ",", OP_STRTAB, 20 },
  239. { "-", OP_NEGATION, 1 } /* Right below exponentiation (JBV) */
  240. };
  241. /* Error messages used more than once */
  242. char err_openfile[] = ERR_OPENFILE;
  243. char err_getmem[] = ERR_GETMEM;
  244. char err_noln[] = ERR_NOLN;
  245. char err_nofn[] = ERR_NOFN;
  246. char err_lnnotfound[] = ERR_LNNOTFOUND;
  247. char err_incomplete[] = ERR_INCOMPLETE;
  248. char err_valoorange[] = ERR_VALOORANGE;
  249. char err_syntax[] = ERR_SYNTAX;
  250. char err_devnum[] = ERR_DEVNUM;
  251. char err_dev[] = ERR_DEV;
  252. char err_opsys[] = ERR_OPSYS;
  253. char err_argstr[] = ERR_ARGSTR;
  254. char err_defchar[] = ERR_DEFCHAR;
  255. char err_mismatch[] = ERR_MISMATCH;
  256. char err_dimnotarray[] =ERR_DIMNOTARRAY;
  257. char err_retnogosub[] = ERR_RETNOGOSUB;
  258. char err_od[] = ERR_OD;
  259. char err_overflow[] = ERR_OVERFLOW;
  260. char err_nf[] = ERR_NF;
  261. char err_uf[] = ERR_UF;
  262. char err_dbz[] = ERR_DBZ;
  263. char err_redim[] = ERR_REDIM;
  264. char err_obdim[] = ERR_OBDIM;
  265. char err_uc[] = ERR_UC;
  266. char err_noprogfile[] = ERR_NOPROGFILE;
  267. /***************************************************************
  268. Error Message Table for Bywater BASIC
  269. ***************************************************************/
  270. char *err_table[ N_ERRORS ] =
  271. {
  272. err_openfile,
  273. err_getmem,
  274. err_noln,
  275. err_nofn,
  276. err_lnnotfound,
  277. err_incomplete,
  278. err_valoorange,
  279. err_syntax,
  280. err_devnum,
  281. err_dev,
  282. err_opsys,
  283. err_argstr,
  284. err_defchar,
  285. err_mismatch,
  286. err_dimnotarray,
  287. err_od,
  288. err_overflow,
  289. err_nf,
  290. err_uf,
  291. err_dbz,
  292. err_redim,
  293. err_obdim,
  294. err_uc,
  295. err_noprogfile
  296. };