emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/parser-generator fe0decba88 50/82: Passed one test for


From: Christian Johansson
Subject: [elpa] externals/parser-generator fe0decba88 50/82: Passed one test for LLk where k=1
Date: Thu, 12 May 2022 13:28:17 -0400 (EDT)

branch: externals/parser-generator
commit fe0decba880dd47ed5a6dc67ec60e767051ac61d
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>

    Passed one test for LLk where k=1
---
 parser-generator-ll.el           | 33 +++++++++++++++++++++------------
 test/parser-generator-ll-test.el | 17 ++++++++---------
 2 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/parser-generator-ll.el b/parser-generator-ll.el
index 3cd5a1825f..dec9f6b668 100644
--- a/parser-generator-ll.el
+++ b/parser-generator-ll.el
@@ -224,6 +224,7 @@
          (message "first-rhs: %S" first-rhs)
          (message "satured-first-rhs: %S" satured-first-rhs))
 
+        ;; Calculate look-aheads
         (cond
          ((and satured-first-rhs
                (not first-parent-follow))
@@ -258,14 +259,12 @@
         ;; push a new item to stack with a local-follow
         ;; and a new left-hand-side
         (let ((sub-symbol-index 0)
-              (sub-symbol-length (length production-rhs)))
+              (sub-symbol-length (length production-rhs))
+              (found-first-non-terminal-p))
           (while (< sub-symbol-index sub-symbol-length)
             (let ((sub-symbol (nth sub-symbol-index production-rhs)))
               (when (parser-generator--valid-non-terminal-p
                      sub-symbol)
-                (parser-generator--debug
-                 (message
-                  "\nnon-terminal sub-symbol: %S" sub-symbol))
                 (let* ((follow-set
                         (nthcdr (1+ sub-symbol-index) production-rhs))
                        (first-follow-set
@@ -280,10 +279,11 @@
                        (sub-symbol-rhss
                         (parser-generator--get-grammar-rhs
                          sub-symbol)))
-                  
                   (parser-generator--debug
                    (message
-                    "\nfollow-set: %S for %S in %S"
+                    "\nnon-terminal sub-symbol: %S" sub-symbol)
+                   (message
+                    "follow-set: %S for %S in %S"
                     follow-set
                     (nth sub-symbol-index production-rhs)
                     production-rhs)
@@ -303,9 +303,14 @@
                     "sub-symbol-rhss: %S"
                     sub-symbol-rhss))
                   (dolist (local-follow local-follow-set)
-                    (push
-                     local-follow
-                     sets)
+                    (unless found-first-non-terminal-p
+                      (parser-generator--debug
+                       (message
+                        "pushed local follow to set: %S"
+                        local-follow))
+                      (push
+                       local-follow
+                       sets))
                     (dolist (sub-symbol-rhs sub-symbol-rhss)
                       (let* ((new-stack-item
                               (list
@@ -325,13 +330,17 @@
                            distinct-stack-item-p)
                           (push
                            new-stack-item
-                           stack))))))))
+                           stack)))))
+                  (unless found-first-non-terminal-p
+                    (setq
+                     found-first-non-terminal-p
+                     t)))))
             (setq
              sub-symbol-index
              (1+ sub-symbol-index))))
 
         ;; Add all distinct combinations of left-hand-side,
-        ;; look-ahead and parent-follow to tables list here
+        ;; look-aheads and parent-follow to tables list here
         (when look-aheads
           (dolist (look-ahead look-aheads)
             (let ((table
@@ -357,7 +366,7 @@
                  t
                  distinct-item-p)
                 (parser-generator--debug
-                 (message "new table: %S" table))
+                 (message "\nnew table: %S" table))
                 (if (gethash
                      table-hash-key
                      tables)
diff --git a/test/parser-generator-ll-test.el b/test/parser-generator-ll-test.el
index d767d76bde..f2267255bf 100644
--- a/test/parser-generator-ll-test.el
+++ b/test/parser-generator-ll-test.el
@@ -135,7 +135,7 @@
   (parser-generator-process-grammar)
   (let* ((tables
           (parser-generator-ll--generate-tables)))
-    (message "tables: %S" tables)
+    ;; (message "tables: %S" tables)
     (should
      (equal
       tables
@@ -144,20 +144,20 @@
          ((A) (a))
          (
           ((a) (a) nil)
-          ((b) (b S A) ((a) (b) (a)))
+          ((b) (b S A) ((b) (a)))
           )
          )
         (
          ((S) (a))
          (
-          ((a) (a A S) ((a) (b) (a)))
+          ((a) (a A S) ((b) (a)))
           ((b) (b) nil)
           )
          )
         (
          ((S) (b))
          (
-          ((a) (a A S) ((b) (b) (a)))
+          ((a) (a A S) ((b) (a)))
           ((b) (b) nil)
           )
          )
@@ -165,20 +165,20 @@
          ((A) (b))
          (
           ((a) (a) nil)
-          ((b) (b S A) ((b) (b) (a)))
+          ((b) (b S A) ((b) (a)))
           )
          )
         (
          ((S) ($))
          (
-          ((a) (a A S) (($) (b) (a))) ;; WEIRD?
+          ((a) (a A S) ((b) (a)))
           ((b) (b) nil)
           )
          )
         )
-      ))
+      )
+     )
     )
-  ;; TODO Verify above
   (message "Passed Example 5.5 p. 340")
 
   ;; TODO Example 5.12 p. 346-347
@@ -460,7 +460,6 @@
     '(0 3 1 2 1) ;; Example is indexed from 1 so that is why they have '(1 4 2 
3 2)
     (parser-generator-ll-parse)))
   (message "Passed example 5.5 p. 340")
-  ;; TODO Make this pass
 
   (parser-generator-set-eof-identifier '$)
   (parser-generator-set-e-identifier 'e)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]