Skip to content

Instantly share code, notes, and snippets.

@timmc
Created March 17, 2011 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timmc/875176 to your computer and use it in GitHub Desktop.
Save timmc/875176 to your computer and use it in GitHub Desktop.
;;;; 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