aboutsummaryrefslogtreecommitdiff
path: root/src/cljcc/token.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/cljcc/token.clj')
-rw-r--r--src/cljcc/token.clj71
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}))