diff options
Diffstat (limited to 'grammar.lisp')
-rw-r--r-- | grammar.lisp | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/grammar.lisp b/grammar.lisp index 2a3cb03..d91317f 100644 --- a/grammar.lisp +++ b/grammar.lisp @@ -18,37 +18,51 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |# -(defun last-char (s) - (char s (- (length s) 1))) - +;; Rules for interpreting the purpose of some line. (setf *grammar* - '((label + '( + (label (lambda (l) - (eq (last-char (first l)) #\:))) - (macro + (and (eq (last-char (first l)) #\:) + (eq (length l) 1)))) + (label-instruction (lambda (l) - (eq (second l) "="))) + (and (eq (last-char (first l)) #\:) + (member (read-from-string (second l)) *opcodes*)))) (attribute (lambda (l) - (eq (char (first l) 0) #\.))) + (equal (char (first l) 0) #\.))) (instruction (lambda (l) - (if (or (member (read-from-string (first l)) *opcodes*) - (member (read-from-string (second l)) *opcodes*)) - t nil))))) + (member (read-from-string (first l)) *opcodes*))) + (macro + (lambda (l) + (equal (second l) "="))) + (unknown + (lambda (l) + t)))) + + +(defun syntax-rule (line list) + "Apply a syntax rule against a delimited line from a program." + (dolist (i (extract-keys list)) + (let ((z (funcall (eval (cadr (assoc i list))) + line))) + (if (not (equal + z nil)) + (return i) + nil)))) + + +(syntax-rule '("LABEL:" "LDA" "$05") *grammar*) + +(syntax-rule '("LDA" "$05") *grammar*) +(syntax-rule '("AS" "=" "THAT") *grammar*) -(defun syntax-rule (item list) - "Test a line against a list of syntax rules." - (dolist (i (extract-keys list)) - (let ((z (funcall - (eval (cadr (assoc i list))) - item))) - (cond ((not (equal - z nil)) - (return i)) - (t nil))))) +(syntax-rule '("LABEL:") *grammar*) -(syntax-rule '("LDA:" "$05") *grammar*) +(syntax-rule '("hhhh") *grammar*) +(syntax-rule '(".org" "$FF00") *grammar*) |