Commits

Anonymous committed fc6ad8b

Small cleanups in grammar

Comments (0)

Files changed (1)

 (defun initial-lr1-item-for-production (production lookahead)
   (make-instance 'lr1-item :position 0 :production production :lookahead lookahead))
 
-(defun initial-lr1-items-for-grammar (specification start-rule-name)
+(defun initial-lr1-state-for-grammar (specification start-rule-name)
   (loop for rule in specification
      if (eql (car rule) start-rule-name)
      return (loop for production in (rule-productions rule)
 		       unless (item-finished-p item)
 		       collect (increment-lr1-item-position item))))
 
-(defun lr1-goto-index-for-symbol ( specification states symbol)
-  (let ((goto (lr1-goto-for-symbol specification states symbol)))
-    (position goto states :test #'equal-items)))
-
-(defun lr1-items-for-grammar (specification start-rule-name)
-  (let ((states (list (closure-of-lr1-items specification (initial-lr1-items-for-grammar specification start-rule-name))))
+(defun lr1-states-for-grammar (specification start-rule-name)
+  (let ((states (list (closure-of-lr1-items specification (initial-lr1-state-for-grammar specification start-rule-name))))
 	(symbols (symbols-in-grammar specification)))
     (loop for done = t
        do (loop for state in states
-	     ;; do (format *standard-output* "State: ~a~%" state)
 	     do (loop for symbol in symbols
 		   do (let ((goto (lr1-goto-for-symbol specification state symbol)))
 			(when (and goto (not (member goto states :test #'equal-items)))
        finally (return (reverse states)))))
 
 (defun make-grammar (specification start-rule-name)
-  (let* ((states (lr1-items-for-grammar specification start-rule-name))
+  (let* ((states (lr1-states-for-grammar specification start-rule-name))
 	 (non-terminals (non-terminals-in-grammar specification))
 	 (action-table (make-instance 'lr-parse-table :states (length states)))
 	 (goto-table (make-instance 'lr-parse-table :states (length states))))