aboutsummaryrefslogtreecommitdiff
path: root/src/cljcc/token.clj
blob: 9136631151d51bd124bfbaa458293c58f92786f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
(ns cljcc.token)

(def token-kind
  #{:eof
    :semicolon

    ;; brackets
    :left-curly
    :right-curly
    :left-paren
    :right-paren

    ;; operators
    :bitwise-not

    :multiply
    :divide
    :remainder

    :plus
    :minus

    :bitwise-left-shift
    :bitwise-right-shift

    :ampersand

    :bitwise-xor

    :bitwise-or

    :negate
    :assignemnt
    :increment
    :decrement

    :number
    :identifier

    ;; keywords
    :kw-return
    :kw-int
    :kw-void})

(def chrs
  #{})

(def bin-ops
  "Binary operanrs and their precedence."
  {:multiply 100
   :divide 100
   :remainder 100
   :plus 90
   :hyphen 90
   :bitwise-left-shift 80
   :bitwise-right-shift 80
   :ampersand 70
   :bitwise-xor 60
   :bitwise-or 50})

(def chrs-kind-map
  {\( :left-paren
   \) :right-paren
   \{ :left-curly
   \} :right-curly
   \= :assignment
   "--" :decrement
   "++" :increment
   "<<" :bitwise-left-shift
   ">>" :bitwise-right-shift
   \^ :bitwise-xor
   \| :bitwise-or
   \& :ampersand
   \; :semicolon
   \+ :plus
   \- :hyphen
   \~ :complement
   \* :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}))