I've begun the task of translating my GLR parser generator from Common Lisp to C. So far I've rewritten the code that parses the grammar definition file and builds the data structures for it. The Common Lisp code that does this is entirely contained in the following three function definitions while the C version is more than 400 lines just for the data structure definitions and functions. Strictly speaking I should also include the 1800 lines of C for the parser driver and the 500 lines for the compiled parser definitions, although this part could probably be rewritten in a few hundred lines as a simple recursive descent parser instead.
Still, that's 23 lines of Common Lisp versus more than 3000 lines of C. The performance, portability, and scalability gains, if any, had better be worth the effort in the long run. :uglystupid2:
(defun read-grammar-name (istream)
(let ((item (read istream nil)))
(when item
(etypecase item
(number item)
(keyword item)
(symbol (symbol-name item))))))
(defun read-grammar-rule (istring)
(when istring
(with-input-from-string (istream istring)
(loop :for token = (read-grammar-name istream)
:while token :unless (keywordp token) :collect token))))
(defun read-grammar-file (file-name)
(let ((*readtable* (copy-readtable nil)))
(setf (readtable-case *readtable*) :preserve)
(with-open-file (istream file-name :direction :input)
(loop :for line = (read-line istream nil)
:for rule = (read-grammar-rule line)
:while line :when rule :collect rule))))