diff options
| author | Nakidai <plaza521@inbox.ru> | 2024-08-24 14:29:55 +0300 |
|---|---|---|
| committer | Nakidai <plaza521@inbox.ru> | 2024-08-24 14:29:55 +0300 |
| commit | c74aea420c662039072f606b2d5ef1c73426e481 (patch) | |
| tree | 4790fa17644df9e11380d6c02b8928c923c20aba /src/readchar.c | |
| parent | 2b0e05cbc1e4d9beccd3a5867c8730880f6ecc10 (diff) | |
| download | 3cl-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 'src/readchar.c')
| -rw-r--r-- | src/readchar.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/readchar.c b/src/readchar.c new file mode 100644 index 0000000..51e1784 --- /dev/null +++ b/src/readchar.c @@ -0,0 +1,59 @@ +#include "3cl.h" +#include "readchar.h" + +#include <stdbool.h> +#include <string.h> + +#include "utils.h" + + +static const char *const space = " \n\t"; +static const char *const brackets = "{[(?;)]}"; +static const char *const instr = "^+-*~%=!$&<>@#:"; +static const char *const alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +char ccl_readchar(struct CCL *ccl, struct CCLFrame *frame, enum CCLRCFlags flags) +{ + bool iscomment; + + char chr; + for (;(chr = ccl->code[frame->ep]) != '\0'; ++frame->ep) + { + if (iscomment && chr == '\n') + iscomment = false; + if (iscomment) + continue; + if (chr == '/') + iscomment = true; + + if (strchr(space, chr)) + continue; + + if (strchr(brackets, chr)) + if (!(flags & CCL_RC_BRACK) && flags & CCL_RC_DIE) + goto invalid; + else + goto ok; + else if (strchr(instr, chr)) + if (!(flags & CCL_RC_IS) && flags & CCL_RC_DIE) + goto invalid; + else + goto ok; + else if (strchr(alphabet, chr)) + if (!(flags & CCL_RC_ALP) && flags & CCL_RC_DIE) + goto invalid; + else + goto ok; + else if (chr == '_') + if (!(flags & CCL_RC_US) && flags & CCL_RC_DIE) + goto invalid; + else + goto ok; + else + goto invalid; + } +ok: + return chr; +invalid: + die(1, "Invalid symbol at %d", frame->ep); +} |