iris

small scheme interpreter
git clone git://git.2f30.org/iris
Log | Files | Refs | LICENSE

commit 4b6f5b43e5e70b0128e966790b142ab38b8cf4af
parent ef4d9841c21e8b70e80e3c3881f96faa1c194c34
Author: sin <sin@2f30.org>
Date:   Fri,  9 May 2014 14:13:46 +0100

Add support for signed numbers

No floating point at the moment.

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

diff --git a/lexer.c b/lexer.c @@ -11,6 +11,7 @@ enum state { State_Probable_Boolean, State_Boolean, State_Number, + State_Signed_Number, State_Probable_Character, State_Character, State_Probable_String, @@ -66,6 +67,8 @@ gettok(struct lexerctx *ctx, const char *buf, size_t len) state = State_Probable_Boolean; else if (isdigit(*ctx->e) != 0) state = State_Number; + else if (*ctx->e == '-' || *ctx->e == '+') + state = State_Signed_Number; else if (*ctx->e == '"') state = State_Probable_String; else if (*ctx->e == '(') @@ -134,6 +137,15 @@ gettok(struct lexerctx *ctx, const char *buf, size_t len) return tok; } break; + case State_Signed_Number: + if (isdigit(*ctx->e) == 0) { + tok.type = Error; + tok.s = "not a number"; + tok.e = NULL; + return tok; + } + state = State_Number; + break; case State_Probable_Character: if (isalpha(*ctx->e) != 0) { state = State_Character;