anchor.diff:    "Attempt to convert this grammar to right-regular form."
     ;; TODO: prune epsilons, singletons, and redundant nonterminals
     ;;       do this using same steps an CNF conversion
  -  (let ((new-grammar (make-finite-set))
  -        (terminals (grammar-terminals grammar))
  -        (nonterminals (grammar-nonterminals grammar)))
  -    (labels ((add-production (lhs rhs)
  -               (setq new-grammar (finite-set-add new-grammar
  -                                                 (cons lhs rhs))))
  -             (add-nonterminal (nonterm)
  -               (setq nonterminals (finite-set-add nonterminals nonterm)))
  -             (simplify (lhs rhs)
  -               (cond
  -                 ;; A -> a | B | :epsilon
  -                 ((and (= 1 (length rhs)))
  -                  (add-production lhs rhs))
  -                 ;; A -> a B
  -                 ((and (= 2 (length rhs))
  -                       (finite-set-member terminals (first rhs))
  -                       (finite-set-member nonterminals (second rhs)))
  -                  (add-production lhs rhs))
  -                 ;; A -> a b ALPHA
  -                 ((and (<= 2 (length rhs))
  -                       (finite-set-member terminals (first rhs))
  -                       (finite-set-member terminals (second rhs)))
  -                  (let ((new-nonterm (gensym "GRAMMAR->RIGHT-REGULAR")))
  -                    (add-production lhs (list (first rhs) new-nonterm))
  -                    (add-nonterminal new-nonterm)
  -                    (simplify new-nonterm (rest rhs))))
  -                 (t (error "Can't handle ~A => ~A" lhs rhs)))))
  -      ;; simplify initially
  -      (grammar-map nil #'simplify grammar))
  -    (cons (list (gensym "START") (grammar-start-nonterminal grammar))
  -          new-grammar)))
  +  (let ((terminals (grammar-terminals grammar)))
  +    (labels ((simplify (grammar)
  +               (when grammar
  +                 (destructuring-bind ((lhs &rest rhs) &rest remaining) grammar
  +                   (cond
  +                     ;; A -> a | B | :epsilon
  +                     ((and (= 1 (length rhs)))
  +                      (cons (car grammar) (simplify (cdr grammar))))
  +                     ;; A -> a B
  +                     ((and (= 2 (length rhs))
  +                           (finite-set-member terminals (first rhs))
  +                           (not (finite-set-member terminals (second rhs))))
  +                      (cons (car grammar) (simplify (cdr grammar))))
  +                     ;; A -> a b ALPHA
  +                     ((and (<= 2 (length rhs))
  +                           (finite-set-member terminals (first rhs))
  +                           (finite-set-member terminals (second rhs)))
  +                      (let ((new-nonterm (gensym "GRAMMAR->RIGHT-REGULAR")))
  +                        (simplify `(,(list lhs (first rhs) new-nonterm)
  +                                     (,new-nonterm ,@(rest rhs))
  +                                     ,@remaining))))
  +                     (t (error "Can't handle ~A => ~A" lhs rhs)))))))
  +      (simplify grammar))))
   
   
   (defun grammar->fa (grammar)
  +  "Convert grammar to a finite automata.
  +GRAMMAR: a right regular grammar (or something close to right regular)
  +RESULT: a finite automaton"
     (unless (grammar-right-regular-p grammar)
       (setq grammar (grammar->right-regular grammar)))
     (let ((terminals (grammar-terminals grammar))
           (nonterminals (grammar-nonterminals grammar))
           (edges)
           (start (caar grammar))
  -        (accept (gensym "ACCEPT-STATE")))
  +        (accept (gensym "ACC")))
       (grammar-map nil
                    (lambda (lhs rhs)
                      (cond
  
positive.code: 
  
  (defun grammar-start-nonterminal (grammar)
    (caar grammar))
  
  (defun grammar-substitute-terminal-list
  
negative.code: ;;;   - prod -> (left-hand-side &rest expansion
  
  
  (defun gsymbol-name (gsym)
    (format nil "~A" gsym))
  
  (defun grammar-map (result function grammar)
    "Applies function to each production in grammar.
  