bydgoszczscript

simple, fast and efficient programming language
git clone git://git.kocotian.pl/bydgoszczscript.git
Log | Files | Refs | README | LICENSE

commit 0ca26b528fee40fe5302ed4876e7b43d697a40dd
parent 9dadeea516058a663fe91dc3530dd1d8f9d19469
Author: kocotian <kocotian@kocotian.pl>
Date:   Wed, 26 May 2021 14:18:27 +0200

New tokens parseability, token stringization

Diffstat:
Mtoken.c | 37+++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+), 0 deletions(-)

diff --git a/token.c b/token.c @@ -73,6 +73,26 @@ nextToken(File *f) while (CURCHAR != '"' && NOT_OVERFLOW) ++i; ++i; } + /* OpeningParenthesis */ + else if ((CURCHAR == '(')) { + TYPE(TokenOpeningParenthesis); + ++i; + } + /* ClosingParenthesis */ + else if ((CURCHAR == ')')) { + TYPE(TokenClosingParenthesis); + ++i; + } + /* Colon */ + else if ((CURCHAR == ':')) { + TYPE(TokenColon); + ++i; + } + /* Semicolon */ + else if ((CURCHAR == ';')) { + TYPE(TokenSemicolon); + ++i; + } /* Other unexpected token */ else { errwarn(*f, 1, "unexpected token: '%c'", CURCHAR); @@ -84,3 +104,20 @@ nextToken(File *f) #undef NOT_OVERFLOW #undef i #undef CURCHAR + +char * +stringizeTokenType(TokenType t) +{ + switch (t) { + case TokenNULL: return "<null>"; break; + case TokenIdentifier: return "identifier"; break; + case TokenNumber: return "number"; break; + case TokenString: return "string"; break; + case TokenOpeningParenthesis: return "opening parenthesis"; break; + case TokenClosingParenthesis: return "closing parenthesis"; break; + case TokenColon: return "colon"; break; + case TokenSemicolon: return "semicolon"; break; + default: break; + } + return "<unknown>"; +}