: ) wonderful world ( :

lalr(1) in cl

Posted in lisp, parser by grault on October 23rd, 2007

Parsing is easy with cl-yacc. With just the

(defun list-lexer (list)
  #'(lambda ()
      (let ((value (pop list)))
	(values value value))))

(define-parser my-parser
    (:start-symbol S)
  (:terminals (a b))
  (S (a S b) ()))

code you’ve already been able to parse like

CL-USER> (parse-with-lexer (list-lexer '(a a b b)) my-parser)
(A (A NIL B) B)
CL-USER>

Leave a Reply