From fdcf4be12c7c8913ccd26ebcab7cb05eb2abaa48 Mon Sep 17 00:00:00 2001 From: bd Date: Mon, 4 Nov 2024 23:34:54 -0500 Subject: Add keywords to lexer --- src/modules/lexer/lexer.scm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/lexer/lexer.scm b/src/modules/lexer/lexer.scm index e07ab67..dae7107 100644 --- a/src/modules/lexer/lexer.scm +++ b/src/modules/lexer/lexer.scm @@ -30,7 +30,7 @@ current input port." 'semi-colon) ((char-alphabetic? chr) - (read-identifier chr)) + (lookup-keyword (read-identifier chr))) ((char-numeric? chr) (read-constant chr)) @@ -57,3 +57,13 @@ current input port." (read-identifier-helper (cons (read-char) chrs-so-far))) (#t (reverse chrs-so-far))))) (list->string (read-identifier-helper (list chr)))) + +(define (lookup-keyword id) + "Given identifier ID, converts it to a keyword +if one is known." + (let ((found (assoc + id + '(("int" . int) + ("void" . void) + ("return" . return))))) + (if found (cdr found) id))) -- cgit v1.2.3