summary refs log tree commit diff
path: root/include/readchar.h
diff options
context:
space:
mode:
authorNakidai <plaza521@inbox.ru>2024-08-24 14:29:55 +0300
committerNakidai <plaza521@inbox.ru>2024-08-24 14:29:55 +0300
commitc74aea420c662039072f606b2d5ef1c73426e481 (patch)
tree4790fa17644df9e11380d6c02b8928c923c20aba /include/readchar.h
parent2b0e05cbc1e4d9beccd3a5867c8730880f6ecc10 (diff)
download3cl-c74aea420c662039072f606b2d5ef1c73426e481.tar.gz
3cl-c74aea420c662039072f606b2d5ef1c73426e481.zip
Add more code
Add some funcitons to work with variables, add more instructions and add
ability to stop the code from `ccl_instruction`
Diffstat (limited to 'include/readchar.h')
-rw-r--r--include/readchar.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/include/readchar.h b/include/readchar.h
new file mode 100644
index 0000000..e881dcb
--- /dev/null
+++ b/include/readchar.h
@@ -0,0 +1,44 @@
+#ifndef __CCL_READCHAR_H__
+#define __CCL_READCHAR_H__
+
+#include "3cl.h"
+
+
+/**
+ * Flags to tell ccl_readchar how to read next character
+ *
+ * Bits
+ * 4 Die if char is not whitelisted
+ * 3 Brackets
+ * 2 Instruction symbols
+ * 1 English alphabet
+ * 0 Underscore
+ *
+ * @see ccl_readchar
+ */
+enum CCLRCFlags
+{
+    CCL_RC_DIE   = 0b10000, /**< Die if char is not whitelisted */
+    CCL_RC_BRACK = 0b01000, /**< Brackes                        */
+    CCL_RC_IS    = 0b00100, /**< Instruction symbols            */
+    CCL_RC_ALP   = 0b00010, /**< English alphabet               */
+    CCL_RC_US    = 0b00001, /**< Underscore                     */
+    CCL_RC_VAR       = 0b11010, /**< (Used by 3CL) Variable names                      */
+    CCL_RC_CCL_VARUS = 0b11011, /**< (Used by 3CL) Variable names including underscore */
+    CCL_RC_CCL_BRACK = 0b01000, /**< (Used by 3CL) Brackets                            */
+    CCL_RC_CCL_INSTR = 0b11111, /**< (Used by 3CL) Instruction                         */
+};
+
+/**
+ * Function to read next character
+ * Skips whitespace and comments, returns '\0' if reaches EOF
+ * ccl_readchar will die on invalid symbol (e.g. cyrillic one) even if CCL_RC_DIE is set
+ * @see CCLRCFlags
+ * @param ccl CCL instance
+ * @param frame Current frame
+ * @param flags CCLRCFlags
+ * @return Next character
+ */
+char ccl_readchar(struct CCL *ccl, struct CCLFrame *frame, enum CCLRCFlags flags);
+
+#endif /* __CCL_READCHAR_H__ */