summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-04-10 21:56:36 -0400
committerbd <bdunahu@operationnull.com>2025-04-10 21:56:36 -0400
commit42ae34d6f2ee0f0eb10e6ecc1e914c5d4753a184 (patch)
tree5c97c17528ee08641588800915805ff4aa80b332 /src
parent0f0dd1012d6b1768eb91f1b35e8a7006d09414ab (diff)
Allow all integers to be negative
Diffstat (limited to 'src')
-rw-r--r--src/parse.lisp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/parse.lisp b/src/parse.lisp
index 6b0d31d..687474b 100644
--- a/src/parse.lisp
+++ b/src/parse.lisp
@@ -18,6 +18,8 @@
(incf line-number)
nil))
+(esrap:defrule sign (or #\+ #\-))
+
(esrap:defrule alpha (+ (alphanumericp character))
(:text t))
@@ -38,7 +40,9 @@
"A" "B" "C" "D" "E" "F")))
(:lambda (e) (parse-integer (esrap:text (cddr e)) :radix 16)))
-(esrap:defrule int (or binary octal hex decimal))
+(esrap:defrule int (and (esrap:? sign) (or binary octal hex decimal))
+ (:destructure (s i)
+ (if (and s (string= s "-")) (- i) i)))
;;; defines rules to parse an operand
@@ -49,10 +53,10 @@
(esrap:defrule var alpha
(:lambda (e) (list (list 'emit::rr 0) (list 'emit::var e))))
-(esrap:defrule dereference (and (esrap:? (or #\+ #\-)) int #\( register #\))
- (:destructure (s i1 w1 r w2)
+(esrap:defrule dereference (and int #\( register #\))
+ (:destructure (i1 w1 r w2)
(declare (ignore w1 w2))
- (list r (list 'emit::imm (if (and s (string= s "-")) (- i1) i1)))))
+ (list r (list 'emit::imm i1))))
(esrap:defrule immediate int
(:lambda (e) (list 'emit::imm e)))