Created
March 17, 2011 21:33
-
-
Save timmc/875176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; fnparse semantics | |
(defn as-decimal-number | |
"Read a sequence of characters as a decimal integer." | |
[[& digit-chars]] | |
(Integer/parseInt (apply str digit-chars) 10)) | |
;;;; basic token classes | |
(def zero-digit (lit \0)) | |
(def nonzero-dec-digit (lit-alt-seq "123456789")) | |
(def decimal-digit (alt zero-digit nonzero-dec-digit)) | |
(def hex-letters (lit-alt-seq "ABCDEFabcdef")) | |
;;;; basic sequences (return strings and numbers) | |
(def reg-num (semantics (rep+ decimal-digit) as-decimal-number)) | |
;;;; semantic atoms (return maps) | |
(def hex-imm (semantics (rep+ decimal-digit) as-decimal-number)) | |
(def register (conc (lit-conc-seq "$r") reg-num)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment