diff options
author | bd <bdunahu@operationnull.com> | 2024-12-31 01:41:03 -0700 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2024-12-31 01:41:03 -0700 |
commit | c4b297fcb0e981591ea8c98339498a68c0a89ce0 (patch) | |
tree | b90e12c1c7020f5cb7b00c5ac3d012f18cef4036 /src/modules | |
parent | af71acaa9f22f17dc1a6ce0737b6255d3af0a7ab (diff) |
Add (and test) sub, add, inc/decrement, and bit-complement to lexer
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/lexer/lexer.scm | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/modules/lexer/lexer.scm b/src/modules/lexer/lexer.scm index a6be215..4078db4 100644 --- a/src/modules/lexer/lexer.scm +++ b/src/modules/lexer/lexer.scm @@ -28,13 +28,25 @@ current input port." 'close-brace) ((eqv? chr #\;) 'semi-colon) + ((eqv? chr #\~) + 'complement) - ((char-alphabetic? chr) - (lookup-keyword (read-identifier chr))) + ((eqv? chr #\+) + (if (take-two? chr) + 'increment + 'add)) + + ((eqv? chr #\-) + (if (take-two? chr) + 'decrement + 'sub)) ((char-numeric? chr) (read-constant chr)) + ((char-alphabetic? chr) + (lookup-keyword (read-identifier chr))) + (#t (error "illegal lexical syntax"))))) (define (read-constant chr) @@ -58,6 +70,11 @@ current input port." (#t (reverse chrs-so-far))))) (list->string (read-identifier-helper (list chr)))) +(define (take-two? chr) + (if (eqv? chr (peek-char)) + (read-char) + #f)) + (define (lookup-keyword id) "Given identifier ID, converts it to a keyword if one is known." |