diff --git a/compiler/scanner.go b/compiler/scanner.go index 3144538..14de6f1 100644 --- a/compiler/scanner.go +++ b/compiler/scanner.go @@ -29,6 +29,12 @@ const ( TOKEN_STR TOKEN_STARSTR + // Macros + TOKEN_ASM + TOKEN_AT_BODY + TOKEN_CURLY_BRACKET_CLOSE + TOKEN_CURLY_BRACKET_OPEN + // Flow Control TOKEN_CASE TOKEN_ELSE @@ -60,7 +66,6 @@ const ( // Reserved Words TOKEN_ARGC TOKEN_ARGV - TOKEN_ASM TOKEN_BANG_EQUAL TOKEN_CONST TOKEN_EQUAL @@ -108,6 +113,10 @@ var reservedWords = []reserved{ reserved{typ: TOKEN_STR, word: "str" }, reserved{typ: TOKEN_STARSTR, word: "*str" }, + // MACROS + reserved{typ: TOKEN_ASM, word: "asm" }, + reserved{typ: TOKEN_AT_BODY, word: "@body" }, + reserved{typ: TOKEN_DASH_DASH_DASH, word: "---" }, reserved{typ: TOKEN_LET, word: "let" }, reserved{typ: TOKEN_IN, word: "in" }, @@ -115,8 +124,8 @@ var reservedWords = []reserved{ reserved{typ: TOKEN_BANG, word: "!" }, reserved{typ: TOKEN_AT, word: "@" }, - reserved{typ: TOKEN_C_BANG, word: "c!" }, - reserved{typ: TOKEN_C_AT, word: "c@" }, + reserved{typ: TOKEN_C_BANG, word: "!c" }, + reserved{typ: TOKEN_C_AT, word: "@c" }, reserved{typ: TOKEN_ELSE, word: "else" }, reserved{typ: TOKEN_FI, word: "fi" }, @@ -127,7 +136,6 @@ var reservedWords = []reserved{ reserved{typ: TOKEN_ARGC, word: "argc" }, reserved{typ: TOKEN_ARGV, word: "argv" }, - reserved{typ: TOKEN_ASM, word: "asm" }, reserved{typ: TOKEN_BANG_EQUAL, word: "!=" }, reserved{typ: TOKEN_CONST, word: "const" }, reserved{typ: TOKEN_EQUAL, word: "=" }, @@ -330,6 +338,8 @@ func TokenizeFile(f string, s string) []Token { } switch { + case c == '{': makeToken(TOKEN_CURLY_BRACKET_OPEN) + case c == '}': makeToken(TOKEN_CURLY_BRACKET_CLOSE) case c == '[': makeToken(TOKEN_BRACKET_OPEN) case c == ']': makeToken(TOKEN_BRACKET_CLOSE) case c == '(': makeToken(TOKEN_PAREN_OPEN) diff --git a/libs/strings.sk b/libs/strings.sk index 3bfd465..262f7d3 100644 --- a/libs/strings.sk +++ b/libs/strings.sk @@ -41,7 +41,7 @@ fn len (int --- int) 0 dup rot < until ++ I 10 / loop ret ; - len ; Returns: ; - The number of characters in teh string. "Stanczyk" returns 8 -fn len (str --- int) let s in 0 0 dup s ptr c@ != until ++ dup s ptr c@ loop done ret +fn len (str --- int) let s in 0 0 dup s ptr @c != until ++ dup s ptr @c loop done ret ; Compares two strings and returns the results of the comparison ; Calling: @@ -53,7 +53,7 @@ fn strequal (str str --- bool) let s1 l1 s2 l2 in l1 l2 = dup if 0 l1 <= until - I s1 ptr c@ I s2 ptr c@ != if false nip leave fi + I s1 ptr @c I s2 ptr @c != if false nip leave fi I -- loop fi done @@ -76,11 +76,11 @@ fn itoa (int ptr) number 0 != if 0 BUFFER_CAP <= until - 0 buffer I + c! + 0 buffer I + !c I -- loop 0 number len 1 - <= until - '0' number 10 % + buffer I + c! + '0' number 10 % + buffer I + !c number 10 / &number ! I -- loop fi