Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defstruct node
- name weight children parent)
- (alexa:define-string-lexer aoc-lexer
- ()
- ("[a-z]+" (return (values 'id (intern $@))))
- ("\\(([0-9]+)\\)" (return (values 'weight (and $1 (parse-integer $1)))))
- ("->" (return '->))
- ("," (return '\,))
- (" |\\n" (values)))
- (yacc:define-parser *aoc-parser*
- (:start-symbol nodes)
- (:terminals (id weight -> \,))
- (nodes
- (node (lambda (n &aux (m (make-hash-table)))
- (setf (gethash (node-name n) m) n)
- m))
- (node nodes (lambda (n ns)
- (setf (gethash (node-name n) ns) n)
- ns)))
- (node
- (id weight children-opt
- (s:op (make-node :name _ :weight _ :children _))))
- (children-opt
- ()
- (-> children (s:op _2)))
- (children
- (id #'list)
- (id \, children (s:op (cons _1 _3)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement