diff options
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) |