From 095cacc7a00eb42fc0a5c5dc9754480dfc56c6a2 Mon Sep 17 00:00:00 2001 From: aleksei Date: Fri, 12 Apr 2024 11:26:27 +1000 Subject: Self contained program parsing --- main.lisp | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'main.lisp') diff --git a/main.lisp b/main.lisp index 2888f89..4ec4440 100644 --- a/main.lisp +++ b/main.lisp @@ -18,13 +18,6 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |# -(setf - *source-file* - (open "/home/aleksei/lisp/wozmon.s")) - -(setf - *source-line-number* - 0) (defun interpret-character (s x) "Interpret meanings of characters." @@ -79,6 +72,44 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA (length word)))))))) +;; Working read-program +(defun read-program (source-filename) + (let ((line (read-line source-filename nil 'EOF))) + (if (equal line 'EOF) + nil + (let ((line-list (extract-words line))) + (if (equal line-list nil) + (progn + (incf *source-line-number*) + (read-program)) + (cons + (list (incf *source-line-number*) + (extract-words line)) + (read-program))))))) + + + +;; Self contained version +(defun program (source-filename) + "Turns an assembly source file into a list, prepended with line numbers." + (let ((source-file (open source-filename)) + (source-line-number 0)) + (labels + ((recurse () + (let ((line (read-line source-file nil 'EOF))) + (if (equal line 'EOF) + nil + (let ((line-list (extract-words line))) + (if (equal line-list nil) + (progn + (incf source-line-number) + (recurse)) + (cons + (list (incf source-line-number) + (extract-words line)) + (recurse)))))))) + (recurse)))) + (defun last-char (s) -- cgit v1.2.3