diff options
author | aleksei <aleksei@aj.org> | 2024-04-12 11:26:27 +1000 |
---|---|---|
committer | aleksei <aleksei@aj.org> | 2024-04-12 11:26:27 +1000 |
commit | 095cacc7a00eb42fc0a5c5dc9754480dfc56c6a2 (patch) | |
tree | 33f7d0cdc0ba4c3d500ab45cd96f38ae01d213a1 /main.lisp | |
parent | ffffba9996d8dcea9dced6e866c215539f515617 (diff) |
Self contained program parsing
Diffstat (limited to 'main.lisp')
-rw-r--r-- | main.lisp | 45 |
1 files changed, 38 insertions, 7 deletions
@@ -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) |