aboutsummaryrefslogtreecommitdiff
path: root/src/cljcc/lexer.clj
diff options
context:
space:
mode:
authorShagun Agrawal <agrawalshagun07@gmail.com>2024-08-30 18:49:17 +0530
committerShagun Agrawal <agrawalshagun07@gmail.com>2024-08-30 18:49:17 +0530
commit276b0c200e5159b1d099ff85aab544480c2ac757 (patch)
tree8cb86289809936901b2a49344818528799fa81da /src/cljcc/lexer.clj
parent7a3e7151ea7e05952ec58648d71d9ed33168109d (diff)
Add compound assignment operators
Added compound assignment operators ( >>==, += etc ) Pass chapter 5 extra credit tests
Diffstat (limited to 'src/cljcc/lexer.clj')
-rw-r--r--src/cljcc/lexer.clj10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/cljcc/lexer.clj b/src/cljcc/lexer.clj
index 8525441..f074ab2 100644
--- a/src/cljcc/lexer.clj
+++ b/src/cljcc/lexer.clj
@@ -12,7 +12,7 @@
(defn lex
([source]
(lex source 0 (lexer-ctx)))
- ([[ch pk :as source] pos {:keys [line col] :as ctx}]
+ ([[ch pk th :as source] pos {:keys [line col] :as ctx}]
(cond
(empty? source) (update ctx :tokens #(conj % (t/create :eof line col)))
(newline? ch) (recur (next source)
@@ -21,6 +21,12 @@
(update :line inc)
(update :col (fn [_] 1))))
(contains?
+ t/chrs-kind-map (str ch pk th)) (recur (next (next (next source)))
+ (+ pos 3)
+ (-> ctx
+ (update :col #(+ % 3))
+ (update :tokens #(conj % (t/create (get t/chrs-kind-map (str ch pk th)) line col)))))
+ (contains?
t/chrs-kind-map (str ch pk)) (recur (next (next source))
(+ pos 2)
(-> ctx
@@ -66,6 +72,6 @@
}"
(pp/pprint
- (lex "int main(void) {return 2;}"))
+ (lex "int main(void) {return int a = 2; a <<= 2;}"))
())