aboutsummaryrefslogtreecommitdiff
path: root/src/cljcc
diff options
context:
space:
mode:
Diffstat (limited to 'src/cljcc')
-rw-r--r--src/cljcc/lexer.clj4
-rw-r--r--src/cljcc/token.clj6
-rw-r--r--src/cljcc/util.clj10
3 files changed, 15 insertions, 5 deletions
diff --git a/src/cljcc/lexer.clj b/src/cljcc/lexer.clj
index d092ea6..61022d9 100644
--- a/src/cljcc/lexer.clj
+++ b/src/cljcc/lexer.clj
@@ -70,8 +70,8 @@
(lex
"
int main() {
- long a = 110;
+ long unsigned a = 110lu;
}
")
- ())
+ ())
diff --git a/src/cljcc/token.clj b/src/cljcc/token.clj
index 3eaa505..6796c0b 100644
--- a/src/cljcc/token.clj
+++ b/src/cljcc/token.clj
@@ -53,7 +53,9 @@
:kw-return
:kw-int
:kw-long
- :kw-void})
+ :kw-void
+ :kw-signed
+ :kw-unsigned})
(def unary-ops
#{:logical-not
@@ -201,6 +203,8 @@
"continue" :kw-continue
"static" :kw-static
"extern" :kw-extern
+ "signed" :kw-signed
+ "unsigned" :kw-unsigned
:identifier))
(defn create
diff --git a/src/cljcc/util.clj b/src/cljcc/util.clj
index d851a62..f75dd5f 100644
--- a/src/cljcc/util.clj
+++ b/src/cljcc/util.clj
@@ -91,13 +91,19 @@
(catch Exception _e
false)))
+(defn- matches-regex [re s]
+ (not (nil? (re-matches re s))))
+
(defn read-number
- "Returns number and number type tuple.
+ "Returns number in string form.
Checks whether number is valid long. If no, checks if it valid int.
Otherwise error."
[s line col]
- (if-let [s (valid-long? s)]
+ (if-let [_ (or (matches-regex #"[0-9]+" s)
+ (matches-regex #"[0-9]+[lL]" s)
+ (matches-regex #"[0-9]+[uU]" s)
+ (matches-regex #"[0-9]+([lL][uU]|[uU][lL])" s))]
s
(exc/lex-error {:line line
:col col})))