Skip to content

Instantly share code, notes, and snippets.

@adolenc
adolenc / parser.lisp
Last active July 10, 2023 20:52
Simple generator of recursive descent parsers in common lisp
;; helper functions
(defun mklist (obj)
"Ensure obj is a list"
(if (listp obj) obj (list obj)))
(defmacro o (&rest fs)
"Macro for composition of functions. Takes a list of functions and produces
a closure as expected:
(o identity (- 12) 1+) => (lambda (&rest args) (identity (- 12 (1+ ,@args))))
@adolenc
adolenc / gist:9ef2b1b2d2de5deccc85
Last active March 27, 2020 01:48
Simple Turing machine simulator
(defparameter *tape* '())
(defparameter *deltas* '())
(defparameter *tape-pos* 0)
(defparameter *q* 0)
(define-condition no-delta (error)
((text :initarg :text :accessor text)))
(defun final-statep (final-states)
"checks whether current state *q* is a final state"