Ivan Boldyrev  committed 7a57cc1

New function nterminal-id
Keywords: new function, nterminal-id

* generator/fg-decl.lisp (nterminal-id):
New function to ease calculation of nonterminal ID.

* fg-common.lisp (generate-tables):
* fg-lalr.lisp (calculate-rm-info):
Use new function.

  • Participants
  • Parent commits e994b02

Comments (0)

Files changed (3)

File generator/fg-common.lisp

                   (pushnew (cons (item-index item)
                                  (item-index new-item))
                            (aref goto-table
-                                 (- (nterm-id nterm)
-                                    terminals-num))
+                                 (nterminal-id nterm grammar))
                            :test #'equal))))
       ;; Reduce or accept
       (dolist (item items)

File generator/fg-decl.lisp

    (id :accessor nterm-id :initarg :id)
    (is-terminal :accessor terminal-p :initarg :is-terminal :initform nil)))
+(declaim (inline nterminal-id))
+(defun nterminal-id (terminal grammar)
+  (- (nterm-id terminal) (first-nterminal-id grammar)))
 (defmethod nterm-name ((name null))

File generator/fg-lalr.lisp

 (defun calculate-rm-info (grammar)
   "Info about rightmost derivations"
-  (let ((nterminal-num (length (grammar-nterminals grammar)))
-        (terminal-num (length (grammar-terminals grammar))))
+  (let ((nterminal-num (length (grammar-nterminals grammar))))
     (dolist (nterminal (grammar-nterminals grammar))
       (let ((array (make-array nterminal-num :initial-element nil)))
-        (setf (aref array (- (nterm-id nterminal) terminal-num))
+        (setf (aref array (nterminal-id nterminal grammar))
               '(nil)) ; Or nil?
         (setf (rm-info nterminal) array)))
     (let ((set (grammar-nterminals grammar)))