diff options
| author | Shagun Agrawal <agrawalshagun07@gmail.com> | 2024-08-11 22:16:47 +0530 |
|---|---|---|
| committer | Shagun Agrawal <agrawalshagun07@gmail.com> | 2024-08-11 22:16:47 +0530 |
| commit | ca4892ea62cfaca99f9174f58500457ea4a87354 (patch) | |
| tree | 1d876fc539fd26179c34f95b8d3c4e5f5b1805e4 /src/cljcc/token.clj | |
| parent | 0f4b96b2b02822abf6f84903366709b1336905a2 (diff) | |
Add lexer
Add custom lexer
Pass chapter 1 lex stages
Diffstat (limited to 'src/cljcc/token.clj')
| -rw-r--r-- | src/cljcc/token.clj | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/cljcc/token.clj b/src/cljcc/token.clj new file mode 100644 index 0000000..6df4f43 --- /dev/null +++ b/src/cljcc/token.clj @@ -0,0 +1,71 @@ +(ns cljcc.token) + +(def token-kind + #{:eof + :semicolon + + ;; brackets + :left-curly + :right-curly + :left-paren + :right-paren + + ;; operators + :plus + :minus + :multiply + :divide + :remainder + :negate + :assignemnt + :ampersand + :bitwise-not + :bitwise-or + :bitwise-xor + :bitwise-left + :increment + :decrement + + :number + :identifier + + ;; keywords + :kw-return + :kw-int + :kw-void}) + +(def chrs + #{}) + +(def chrs-kind-map + {\( :left-paren + \) :right-paren + \{ :left-curly + \} :right-curly + \= :assignment + "--" :decrement + "++" :increment + \; :semicolon + \+ :plus + \- :minus + \* :multiply + \% :remainder + \/ :divide}) + +(defn identifier->kind [identifier] + (case identifier + "return" :kw-return + "void" :kw-void + "int" :kw-int + :identifier)) + +(defn create + ([kind line col] + {:kind kind + :line line + :col col}) + ([kind line col literal] + {:kind kind + :line line + :col col + :literal literal})) |
