1// This file is part of SmallBASIC
2//
3// Generic keywords : BC size = 1 byte = 255-2 names
4// Buildin functions : BC size = 2 (4 on Unix) bytes = 32K-~1K names
5// Buildin procedures: BC size = 2 (4 on Unix) bytes = 32K-~1K names
6// I had changed the starting values for debuging purposes
7//
8// This program is distributed under the terms of the GPL v2.0 or later
9// Download the GNU Public License (GPL) from www.gnu.org
10//
11// Copyright(C) 2000 Nicholas Christopoulos
12
13#if !defined(_sb_kw_h)
14#define _sb_kw_h
15
16#if defined(__cplusplus)
17extern "C" {
18#endif
19
20/*
21 * operators
22 */
23#define OPLOG_GT '>'
24#define OPLOG_LT '<'
25#define OPLOG_EQ '='
26#define OPLOG_GE 11 // >=
27#define OPLOG_LE 12 // <=
28#define OPLOG_NE 14 // <>
29#define OPLOG_AND '&' // AND
30#define OPLOG_OR '|' // OR
31#define OPLOG_NOT '!' // NOT
32#define OPLOG_XOR '~' // XOR
33#define OPLOG_BAND 'A' // AND (bit)
34#define OPLOG_BOR 'B' // OR (bit)
35#define OPLOG_INV 'C' // Invert (bit)
36#define OPLOG_EQV 'D' // EQV (bit)
37#define OPLOG_IMP 'E' // IMP (bit)
38#define OPLOG_NAND 'F' // NAND (bit)
39#define OPLOG_NOR 'G' // NOR (bit)
40#define OPLOG_XNOR 'H' // XNOR (bit)
41#define OPLOG_IN 'I' // IN (list)
42#define OPLOG_MOD 'M' // MOD (remain)
43#define OPLOG_MDL 'L' // MDL (modulus)
44#define OPLOG_LIKE 'W' // LIKE wc
45#define OPLOG_LSHIFT 'X' // LSHIFT
46#define OPLOG_RSHIFT 'Y' // RSHIFT
47
48/**
49 * @ingroup sys
50 * @enum keyword
51 *
52 * Generic keyword codes
53 *
54 * special commands like PRINT, INPUT, LINE (ex: LINE INPUT)
55 * special seperators too like INPUT, APPEND, FORSEP
56 * and, of course, root commands like REPEAT-UNTIL, IF, etc
57 */
58enum keyword {
59 kwTYPE_INT = 0x1, /* 32b Integer */
60 kwTYPE_NUM, /* 64b Real */
61 kwTYPE_ADDOPR, /* ADD/SUB operator */
62 kwTYPE_MULOPR, /* MUL/DIV/IDIV operator */
63 kwTYPE_VAR, /* Variable */
64 kwTYPE_LEVEL_BEGIN, /* Parenthesis ( */
65 kwTYPE_LEVEL_END, /* Parenthesis ) */
66 kwTYPE_EVPUSH, /* PUSH R */
67 kwTYPE_EVPOP, /* POP L */
68 kwTYPE_CALLF, /* Call a build-in function */
69 kwTYPE_STR, /* String */
70 kwTYPE_LOGOPR, /* Logical operator */
71 kwTYPE_CMPOPR, /* Comparation operator */
72 kwTYPE_POWOPR, /* POW(x,y) operator */
73 kwTYPE_UNROPR, /* Unary operator */
74 kwTYPE_EVAL_SC, /* Evalulation short-circuit begin */
75 kwTYPE_CALL_UDF, /* Call user defined function */
76 kwTYPE_CALLEXTF, /* Call an external function */
77 kwTYPE_PTR, /* Address pointer, eg f=@foo */
78 kwBYREF, /* end eval switch block */
79 kwTYPE_CALL_UDP, /* Call user defined procedure */
80 kwTYPE_CALL_PTR, /* Call user defined procedure or function from address pointer */
81 kwTYPE_CALL_VFUNC, /* Call virtual function */
82 kwTYPE_CALLEXTP, /* Call an external procedure */
83 kwTYPE_CRVAR, /* Create dynamic variable (PARAMETERS OR LOCALS) */
84 kwTYPE_RET, /* Return from UDF|UDP */
85 kwTYPE_PARAM, /* Parameters */
86 kwTYPE_CALLP, /* Call a build-in procedure */
87 kwTYPE_EOC, /* End-Of-Command mark */
88 kwTYPE_UDS_EL, /* Structure element */
89 kwTYPE_SEP, /* Separator */
90 kwTYPE_LINE, /* Debug info: SOURCE LINE */
91 kwLOCAL, /* Create local variables */
92 kwFUNC, /* USER DEFINED FUNCTION */
93 kwPROC, /* USER DEFINED PROCEDURE */
94 kwDECLARE,
95 kwIMPORT,
96 kwEXPORT,
97 kwUNIT,
98 kwLET,
99 kwLET_OPT,
100 kwCONST,
101 kwPACKED_LET,
102 kwEND,
103 kwSTOP,
104 kwPRINT,
105 kwUSING,
106 kwINPUT,
107 kwSINPUT,
108 kwINPUTSEP,
109 kwLOOPSEP,
110 kwPROCSEP,
111 kwFUNCSEP,
112 kwREM,
113 kwLABEL,
114 kwGOTO,
115 kwIF,
116 kwTHEN,
117 kwELSE,
118 kwELIF,
119 kwENDIF,
120 kwFOR,
121 kwTO,
122 kwSTEP,
123 kwIN,
124 kwNEXT,
125 kwWHILE,
126 kwWEND,
127 kwREPEAT,
128 kwUNTIL,
129 kwGOSUB,
130 kwRETURN,
131 kwEXIT,
132 kwLOOP,
133 kwDIM,
134 kwREDIM,
135 kwCHAIN,
136 kwREAD,
137 kwRESTORE,
138 kwDATA,
139 kwCOLOR,
140 kwFILLED,
141 kwLINE,
142 kwON,
143 kwOFF,
144 kwTRON,
145 kwTROFF,
146 kwONJMP,
147 kwRUN,
148 kwEXEC,
149 kwERASE,
150 kwUSE,
151 kwFORSEP,
152 kwOUTPUTSEP,
153 kwAPPEND,
154 kwINSERT,
155 kwDELETE,
156 kwAPPENDSEP,
157 kwOPEN,
158 kwAS,
159 kwFILEPRINT,
160 kwLINEINPUT,
161 kwFILEINPUT,
162 kwFILEWRITE,
163 kwFILEREAD,
164 kwCLOSE,
165 kwSEEK,
166 kwSPRINT,
167 kwDO,
168 kwOPTION,
169 kwBACKG,
170 kwLOGPRINT,
171 kwSELECT,
172 kwCASE,
173 kwCASE_ELSE,
174 kwENDSELECT,
175 kwTRY,
176 kwCATCH,
177 kwENDTRY,
178 kwFUNC_RETURN,
179 kwNULL
180};
181
182/**
183 * @ingroup sys
184 * @enum proc_keywords
185 *
186 * buildin procedures - keyword codes
187 */
188enum proc_keywords {
189 kwCLS = 0x100, // 256 (generic keywords)
190 kwENVIRON,
191 kwLOCATE,
192 kwAT,
193 kwPEN,
194 kwDATEDMY,
195 kwBEEP,
196 kwSOUND,
197 kwNOSOUND,
198 kwPSET,
199 kwRECT,
200 kwCIRCLE,
201 kwRANDOMIZE,
202 kwSPLIT,
203 kwWJOIN,
204 kwPAUSE,
205 kwDELAY,
206 kwARC,
207 kwDRAW,
208 kwPAINT,
209 kwPLAY,
210 kwSORT,
211 kwSEARCH,
212 kwROOT,
213 kwDIFFEQ,
214 kwCHART,
215 kwWINDOW,
216 kwVIEW,
217 kwDRAWPOLY,
218 kwM3IDENT,
219 kwM3ROTATE,
220 kwM3SCALE,
221 kwM3TRANSLATE,
222 kwM3APPLY,
223 kwSEGINTERSECT,
224 kwPOLYEXT,
225 kwDERIV,
226 kwLOADLN,
227 kwSAVELN,
228 kwKILL,
229 kwRENAME,
230 kwCOPY,
231 kwCHDIR,
232 kwMKDIR,
233 kwRMDIR,
234 kwFLOCK,
235 kwCHMOD,
236 kwPLOT,
237 kwSTKDUMP,
238 kwSWAP,
239 kwDIRWALK,
240 kwBPUTC,
241 kwBLOAD,
242 kwBSAVE,
243 kwTIMEHMS,
244 kwEXPRSEQ,
245 kwCALLCP,
246 kwDEFINEKEY,
247 kwSHOWPAGE,
248 kwTHROW,
249 kwNULLPROC
250};
251
252/**
253 * @ingroup sys
254 * @enum func_keywords
255 *
256 * buildin functions - keyword codes
257 */
258enum func_keywords {
259 kwASC = 0x200,
260 kwVAL,
261 kwCHR,
262 kwSTR,
263 kwOCT,
264 kwHEX,
265 kwLCASE,
266 kwUCASE,
267 kwLTRIM,
268 kwRTRIM,
269 kwSPACE,
270 kwTAB,
271 kwCAT,
272 kwENVIRONF,
273 kwTRIM,
274 kwSTRING,
275 kwSQUEEZE,
276 kwLEFT,
277 kwRIGHT,
278 kwLEFTOF,
279 kwRIGHTOF,
280 kwLEFTOFLAST,
281 kwRIGHTOFLAST,
282 kwMID,
283 kwREPLACE,
284 kwRUNF,
285 kwINKEY,
286 kwTIME,
287 kwDATE,
288 kwINSTR,
289 kwRINSTR,
290 kwLBOUND,
291 kwUBOUND,
292 kwLEN,
293 kwEMPTY,
294 kwISARRAY,
295 kwISNUMBER,
296 kwISSTRING,
297 kwISMAP,
298 kwATAN2,
299 kwPOW,
300 kwROUND,
301 kwSIN,
302 kwASIN,
303 kwSINH,
304 kwASINH,
305 kwCOS,
306 kwACOS,
307 kwCOSH,
308 kwACOSH,
309 kwTAN,
310 kwATAN,
311 kwTANH,
312 kwATANH,
313 kwSEC,
314 kwASEC,
315 kwSECH,
316 kwASECH,
317 kwCSC,
318 kwACSC,
319 kwCSCH,
320 kwACSCH,
321 kwCOT,
322 kwACOT,
323 kwCOTH,
324 kwACOTH,
325 kwSQR,
326 kwABS,
327 kwEXP,
328 kwLOG,
329 kwLOG10,
330 kwFIX,
331 kwINT,
332 kwCDBL,
333 kwDEG,
334 kwRAD,
335 kwPENF,
336 kwFLOOR,
337 kwCEIL,
338 kwFRAC,
339 kwFRE,
340 kwSGN,
341 kwCINT,
342 kwEOF,
343 kwSEEKF,
344 kwLOF,
345 kwRND,
346 kwMAX,
347 kwMIN,
348 kwABSMAX,
349 kwABSMIN,
350 kwSUM,
351 kwSUMSV,
352 kwSTATMEAN,
353 kwSTATMEANDEV,
354 kwSTATSPREADS,
355 kwSTATSPREADP,
356 kwSEGCOS,
357 kwSEGSIN,
358 kwSEGLEN,
359 kwPOLYAREA,
360 kwPOLYCENT,
361 kwPTDISTSEG,
362 kwPTSIGN,
363 kwPTDISTLN,
364 kwPOINT,
365 kwCODEARRAY,
366 kwGAUSSJORDAN,
367 kwFILES,
368 kwINVERSE,
369 kwDETERM,
370 kwJULIAN,
371 kwDATEFMT,
372 kwWDAY,
373 kwIFF,
374 kwFORMAT,
375 kwFREEFILE,
376 kwTICKS,
377 kwTIMER,
378 kwPROGLINE,
379 kwINPUTF,
380 kwTEXTWIDTH,
381 kwTEXTHEIGHT,
382 kwEXIST,
383 kwISFILE,
384 kwISDIR,
385 kwISLINK,
386 kwACCESSF,
387 kwXPOS,
388 kwYPOS,
389 kwRGB,
390 kwRGBF,
391 kwBIN,
392 kwENCLOSE,
393 kwDISCLOSE,
394 kwTRANSLATEF,
395 kwCHOP,
396 kwBGETC,
397 kwSEQ,
398 kwCBS,
399 kwBCS,
400 kwCALLCF,
401 kwARRAY,
402 kwIMAGE,
403 kwFORM,
404 kwTIMESTAMP,
405 kwNULLFUNC
406};
407
408/**
409 * @ingroup sys
410 *
411 * checks if the 'code' belongs to the codes that contained in table
412 *
413 * @param code the code to search for
414 * @param table the table of codes to scan
415 * @return non-zero on success
416 */
417int kw_check(code_t *table, code_t code);
418
419/**
420 * @ingroup sys
421 *
422 * returns true if the 'code' is valid code for end-of-expression
423 *
424 * @return non-zero if the 'code' is valid code for end-of-expression
425 */
426int kw_check_evexit(code_t code);
427
428/**
429 * @ingroup sys
430 *
431 * returns the name which is assigned to code
432 *
433 * @param code is the code
434 * @param dest is the buffer to store the keyword
435 * @return non-zero on success
436 */
437int kw_getcmdname(code_t code, char *dest);
438
439/**
440 * @ingroup sys
441 *
442 * returns the name which is assigned to build-in function code
443 *
444 * @param code is the code
445 * @param dest is the buffer to store the keyword
446 * @return non-zero on success
447 */
448int kw_getfuncname(bid_t code, char *dest);
449
450/**
451 * @ingroup sys
452 *
453 * returns the name which is assigned to build-in procedure code
454 *
455 * @param code is the code
456 * @param dest is the buffer to store the keyword
457 * @return non-zero on success
458 */
459int kw_getprocname(bid_t code, char *dest);
460
461/**
462 * @ingroup sys
463 *
464 * returns true if the code is a function without parameters
465 *
466 * @param code is the code
467 * @return non-zero if 'code' is a function that does not requires parameters
468 */
469int kw_noarg_func(bid_t code);
470
471#define OPTION_BASE 1
472#define OPTION_MATCH 4
473
474#if defined(__cplusplus)
475}
476#endif
477#endif
478