Anonymous avatar Anonymous committed 999b22f

Minor improvements to reduction; fixed bug where terms where reduced in reverse order.

Comments (0)

Files changed (4)

 ;; ---------------------------------------------------------------------------------------------------------------------
 ;; Reductions
 
-(defun ignore-terms (&rest args)
+(defun list-terms (rule-name &rest args)
+  (declare (ignorable rule-name))
+  args)
+
+(defun ignore-terms (rule-name &rest args)
   (declare (ignorable args))
-  nil)
+  rule-name)
 
 ;; ---------------------------------------------------------------------------------------------------------------------
 ;;

package-hh-parse.lisp

    #:defgrammar
    #:specification
    #:reduction
+
+   ;; grammar -- reduction actions
    #:ignore-terms
+   #:list-terms
 
    ;; lexers
    #:deflexer
     expected))
 
 (defun reduce-production (production symbol-values)
-  (apply (reduction production) symbol-values))
+  (apply (reduction production) (rule-name production) symbol-values))
 
 (defun parse-token (parser token)
   "Advance the state of the parser by parsing a single token; does not assume token came from lexer"
 			    ((equal :reduce op)
 			     (let* ((production arg)
 				    (reduced-term (reduce-production production 
-								     (loop for i from 1 to (length (slot-value production 'rhs))
-									collect (destructuring-bind (stack-state stack-token) (pop (stack parser))
-										  (declare (ignorable stack-state))
-										  stack-token)))))
+								     ;; we reverse the values, because they were on stack in reverse
+								     (reverse (loop for i from 1 to (length (slot-value production 'rhs))
+										 collect (destructuring-bind (stack-state stack-token) (pop (stack parser))
+											   (declare (ignorable stack-state))
+											   stack-token))))))
 			       (destructuring-bind (new-stack-state new-stack-token) (car (stack parser))
 				 (declare (ignorable new-stack-token))
 				 (push (list (gethash (list new-stack-state (slot-value production 'rule-name )) (entries (gotos grammar))) 
 
 (defclass production ()
   ((rule-name :initarg :rule :accessor rule-name)
-   (reduction :initform #'list :initarg :reduction :accessor reduction)
+   (reduction :initform #'list-terms :initarg :reduction :accessor reduction)
    (rhs :initarg :rhs)))
 
 (defclass lr1-item ()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.