From 44355ceb4db780b370d148008c5048a5075b3978 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Wed, 13 Apr 2022 00:55:46 -0400 Subject: Numeric literals --- tnslc/parse/token.tnsl | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tnslc/parse/token.tnsl') diff --git a/tnslc/parse/token.tnsl b/tnslc/parse/token.tnsl index 668312b..6c402fd 100644 --- a/tnslc/parse/token.tnsl +++ b/tnslc/parse/token.tnsl @@ -250,6 +250,38 @@ ;return false ;/ +/; is_numeric_literal(~{}charp dat) [bool] + /; if (len dat` == 0) + ;return false + ;/ + + ;bool dec = true, flt = false + + ;int i = 0 + + /; if (len dat` > 1) + /; if (dat`{0} == '0' && !is_digit(dat`{1}) && dat`{1} !== '.') + ;dec = false + ;i = 2 + ;/ + ;/ + + /; loop (i < len dat`) [i++] + /; if (!is_digit(dat`{i}) && dec) + /; if (dat`{i} == '.') + /; if (flt || !dec) + ;return false + ;/ + ;flt = true + ;; else if (dec) + ;return false + ;/ + ;/ + ;/ + + ;return true +;/ + /# Get the token_type value for a given string of character points @@ -257,6 +289,10 @@ /; if (len s` > 1) + /; if (is_numeric_literal(s)) + ;return TOKEN_TYPE.LITERAL + ;/ + /; if (is_in_string_list(~PREWORDS, s)) ;return TOKEN_TYPE.PREWORD ;; else if (is_in_string_list(~KEYTYPES, s)) -- cgit v1.2.3