summaryrefslogtreecommitdiff
path: root/main.lisp
blob: e4dd9c4eaeaf794059da17b2820d42859fd8cfdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
;; -*- mode: common-lisp -*-

(setf
 *source-file*
 (open  "/home/aleksei/lisp/wozmon.s"))

(setf
 *source-line-number*
 0)

(defun interpret-character (s x)
  "Interpret meanings of characters."
  (cond
	((>= x (length s))
	 'end-of-line)
	(t
	 ;; Have character, interpret
	 (let ((c (char s x)))
	   (cond
		 ((eq c #\;) ; Comment
		  'comment)
		 ((eq c #\ ) ; Space
		  'whitespace)
		 (t
		  'normal))))))

(defun extract-word (line-string index)
  "Extract a single word from line-string, starting at index."
  (cond
	((member (interpret-character line-string index)
			 `(end-of-line comment))
	 'end-of-line)
	((equal (interpret-character line-string index)
			'whitespace)
	 'whitespace)
	(t
	 (subseq
	  line-string
	  index
	  (do ((end index (incf end)))
		  ((not (equal 'normal
					   (interpret-character line-string end)))
		   end))))))

(defun extract-words (line-string &optional (index 0))
  "Return a list the constituent word strings of line-string."
  ;; Word Processing Logic
  (let ((word (extract-word line-string index)))
	(cond
	  ;; Terminate execution at end-of-line.
	  ((equal word 'end-of-line)
	   nil)
	  ;; If empty, continue on.
	  ((equal word 'whitespace)
	   (extract-words line-string (+ index 1)))
	  ;; Otherwise, extract word and move ahead.
	  (t
	   (cons word
			 (extract-words line-string
							(+ index
							   (length word))))))))




(defun last-char (s)
  (char s (- (length s) 1)))

(defun label? (s)
  (eq (last-char s) #\:))


(setf
 *grammar*
 (('label
   (lambda (l)
	 ))))

(defun read_code ()
  (incf *source-line-number*)
  ()
  )