summaryrefslogtreecommitdiff
path: root/grammar.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'grammar.lisp')
-rw-r--r--grammar.lisp100
1 files changed, 84 insertions, 16 deletions
diff --git a/grammar.lisp b/grammar.lisp
index d91317f..f0c0e10 100644
--- a/grammar.lisp
+++ b/grammar.lisp
@@ -18,9 +18,9 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|#
-;; Rules for interpreting the purpose of some line.
-(setf
- *grammar*
+;; Rules for the interpretation of lines.
+(defparameter
+ *line-syntax*
'(
(label
(lambda (l)
@@ -43,6 +43,87 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
(lambda (l)
t))))
+;; Rules for identifying addressing modes.
+(defparameter
+ *addressing-modes-syntax*
+ '((immediate ; #?? ... more complex syntax rules for later
+ (lambda (s)
+ (eq "#" (subseq s 0 1))))
+ (absolute ;"$????"
+ (lambda (s)
+ (and
+ (equal (length s) 5)
+ (equal "$" (subseq s 0 1))
+ (hexd? (subseq s 1 5)))))
+ (zero-page ;"$??"
+ (lambda (s)
+ (and
+ (equal (length s) 3)
+ (equal "$" (subseq s 0 1))
+ (hexd? (subseq s 1 3)))))
+ (implied nil)
+ (indirect-absolute ;($????)
+ (lambda (s)
+ (and
+ (equal (length s) 7)
+ (equal "($" (subseq s 0 2))
+ (hexd? (subseq s 1 5))
+ (equal ")" (subseq s 5 6)))))
+ (absolute-indexed-x ;"$????,X"
+ (lambda (s)
+ (and
+ (equal (length s) 7)
+ (equal "$" (subseq s 0 1))
+ (hexd? (subseq s 1 5))
+ (equal ",X" (subseq s 5 7)))))
+ (absolute-indexed-y ;"$????,Y"
+ (lambda (s)
+ (and
+ (equal (length s) 7)
+ (equal "$" (subseq s 0 1))
+ (hexd? (subseq s 1 5))
+ (equal ",Y" (subseq s 5 7)))))
+ (zero-page-indexed-x ;"$??,X"
+ (lambda (s)
+ (and
+ (equal (length s) 5)
+ (equal (subseq s 0 1) "$")
+ (hexd? (subseq s 1 3))
+ (equal (subseq s 3 5) ",X"))))
+ (zero-page-indexed-y ;"$??,Y"
+ (lambda (s)
+ (and
+ (equal (length s) 5)
+ (equal (subseq s 0 1) "$")
+ (hexd? (subseq s 1 3))
+ (equal (subseq s 3 5) ",Y"))))
+ (indexed-indirect ;"($??,X)"
+ (lambda (s)
+ (and
+ (equal (length s) 7)
+ (equal (subseq s 0 2) "($")
+ (hexd? (subseq s 2 4))
+ (equal (subseq s 4 7) ",X)"))))
+ (indirect-indexed ;"($??),Y"
+ (lambda (s)
+ (and
+ (equal (length s) 7)
+ (equal (subseq s 0 2) "($")
+ (hexd? (subseq s 2 4))
+ (equal (subseq s 4 7) "),Y"))))
+ ;;How to fix that relative and absolute are the same rule?
+ ;;A check upstream would suffice.
+ (relative ;"$????"
+ (lambda (s)
+ (and
+ (equal (length s) 5)
+ (equal (subseq s 0 1) "$")
+ (hexd? (subseq s 1 5)))))
+ (accumulator ;"A"
+ (lambda (s)
+ (and
+ (equal (length s) 1)
+ (equal "A" (subseq s 0 1)))))))
(defun syntax-rule (line list)
"Apply a syntax rule against a delimited line from a program."
@@ -53,16 +134,3 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
z nil))
(return i)
nil))))
-
-
-(syntax-rule '("LABEL:" "LDA" "$05") *grammar*)
-
-(syntax-rule '("LDA" "$05") *grammar*)
-
-(syntax-rule '("AS" "=" "THAT") *grammar*)
-
-(syntax-rule '("LABEL:") *grammar*)
-
-(syntax-rule '("hhhh") *grammar*)
-
-(syntax-rule '(".org" "$FF00") *grammar*)