hyc

Hydrogen Compiler written in C
git clone git://git.kocotian.pl/hyc.git
Log | Files | Refs | README | LICENSE

commit d22835930aebfec0d46115637f397256d98990f1
parent d5a527ed31beb52e35fceb4dcc2287c51ca18d0f
Author: kocotian <kocotian@kocotian.pl>
Date:   Mon, 26 Jul 2021 14:13:35 +0000

More tokens

Diffstat:
Minclude/tokenize.h | 5++++-
Mtokenize.c | 30+++++++++++++++++++++++++++++-
2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/include/tokenize.h b/include/tokenize.h @@ -29,7 +29,10 @@ typedef enum { TokenOpeningParenthesis, TokenClosingParenthesis, TokenOpeningBracket, TokenClosingBracket, TokenOpeningBrace, TokenClosingBrace, - TokenExclamationMark, + TokenExclamationMark, TokenAssignment, + TokenNotEqual, TokenEqual, + TokenMinus, TokenMinusMinus, TokenMinusEqual, + TokenPlus, TokenPlusPlus, TokenPlusEqual, TokenAsterisk, TokenAmperstand, TokenSemicolon, TokenComma, TokenDot, TokenColon, TokenDoubleColon, diff --git a/tokenize.c b/tokenize.c @@ -89,6 +89,35 @@ tokenize(String input, Token **output) SEEKCHAR; while (CURCHAR != '"' && NOT_OVERFLOW) SEEKCHAR; SEEKCHAR; + /* Unary and conditional operators */ + } else if (CURCHAR == '!') { + TYPE(ExclamationMark); + if (NEXTCHAR == '=') { + TYPE(NotEqual); SEEKCHAR; + } + SEEKCHAR; + } else if (CURCHAR == '=') { + TYPE(Assignment); + if (NEXTCHAR == '=') { + TYPE(Equal); SEEKCHAR; + } + SEEKCHAR; + } else if (CURCHAR == '-') { + TYPE(Minus); + if (NEXTCHAR == '-') { + TYPE(MinusMinus); SEEKCHAR; + } else if (NEXTCHAR == '=') { + TYPE(MinusEqual); SEEKCHAR; + } + SEEKCHAR; + } else if (CURCHAR == '+') { + TYPE(Plus); + if (NEXTCHAR == '+') { + TYPE(PlusPlus); SEEKCHAR; + } else if (NEXTCHAR == '=') { + TYPE(PlusEqual); SEEKCHAR; + } + SEEKCHAR; /* Brackets */ } else if (CURCHAR == '(') { TYPE(OpeningParenthesis); SEEKCHAR; } else if (CURCHAR == ')') { TYPE(ClosingParenthesis); SEEKCHAR; @@ -97,7 +126,6 @@ tokenize(String input, Token **output) } else if (CURCHAR == '{') { TYPE(OpeningBrace); SEEKCHAR; } else if (CURCHAR == '}') { TYPE(ClosingBrace); SEEKCHAR; /* Other single-char operators */ - } else if (CURCHAR == '!') { TYPE(ExclamationMark); SEEKCHAR; } else if (CURCHAR == '*') { TYPE(Asterisk); SEEKCHAR; } else if (CURCHAR == '&') { TYPE(Amperstand); SEEKCHAR; } else if (CURCHAR == ';') { TYPE(Semicolon); SEEKCHAR;