diff options
author | mRnea <akannemre@gmail.com> | 2024-08-03 20:18:21 +0300 |
---|---|---|
committer | mRnea <akannemre@gmail.com> | 2024-08-03 20:18:21 +0300 |
commit | d98974584558ca32db04fc6a47a692dc4ba0143d (patch) | |
tree | 6c5bf4da730179e45dba443a216563f881db158d /cl-forth.lisp | |
parent | 2cbb10fc6b1daacfc331880ef39245307e976b1d (diff) |
fixed "|" :string and | :identifier confusion
Diffstat (limited to 'cl-forth.lisp')
-rw-r--r-- | cl-forth.lisp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/cl-forth.lisp b/cl-forth.lisp index d935956..1026253 100644 --- a/cl-forth.lisp +++ b/cl-forth.lisp @@ -1,9 +1,16 @@ (in-package :cl-forth) -(defun make-token (sym? line col) - (if (or (numberp sym?) (stringp sym?) (is-identifier sym?)) - (values (list sym? :line line :col col) nil) - (values (list sym? :line line :col col :error t) t))) +(defun make-token (sym? line col &optional (type nil)) + (when (null type) + (setf type + (cond ((numberp sym?) :number) + ((stringp sym?) :string) + ((is-identifier sym?) :identifier) + (t + ;; temporary hack... + (return-from make-token + (values (list sym? :line line :col col :error t) t)))))) + (values (list sym? :line line :col col :type type) nil)) (defun token-op (token) (car token)) @@ -32,7 +39,7 @@ ;; (read-char line-stream)) ((char= #\| next-char) (read-char line-stream) - (collect (make-token "|" line-num col) into tokens)) + (collect (make-token "|" line-num col :identifier) into tokens)) ((char= #\Space next-char) (read-char line-stream)) ((char= #\; next-char) ;; and not in string (finish)) @@ -109,10 +116,11 @@ (with stack = ()) (for i from 0) (for token in tokens) - (let ((op (token-op token))) - (cond ((numberp op) + (let ((op (token-op token)) + (op-type (getf (cdr token) :type))) + (cond ((eq :number op-type) (vector-push-extend `(push-int ,op) ops)) - ((stringp op) + ((eq :string op-type) (vector-push-extend `(push-str ,(length op) ,i ,op) ops)) ((string= 'ise op) |