[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/parser-generator 6e91a4b498 32/82: More work on helper
From: |
Christian Johansson |
Subject: |
[elpa] externals/parser-generator 6e91a4b498 32/82: More work on helper functions |
Date: |
Thu, 12 May 2022 13:28:15 -0400 (EDT) |
branch: externals/parser-generator
commit 6e91a4b498e87106222a419789044e61498158d2
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
More work on helper functions
---
parser-generator-ll.el | 16 +++++++++-------
parser-generator.el | 29 ++++++++++++++++++++++-------
test/parser-generator-test.el | 17 ++++++++++++-----
3 files changed, 43 insertions(+), 19 deletions(-)
diff --git a/parser-generator-ll.el b/parser-generator-ll.el
index 5345ec0724..973571e575 100644
--- a/parser-generator-ll.el
+++ b/parser-generator-ll.el
@@ -85,41 +85,43 @@
(parser-generator--debug
(message "\nproduction-lhs: %S" production-lhs)
(message "production-rhs: %S" production-rhs)
- (message "parent-follow: %S" parent-follow))
+ (message "parent-follow: %S" parent-follow)
+ (message "first-rhs: %S" first-rhs)
+ (message "satured-first-rhs: %S" satured-first-rhs))
;; TODO Remove items in first-rhs that ends with the e-identifier
;; TODO but only if it has other items that does not end with the
e-identifier
;; F('((a e) (a a))) = ((a a))
(cond
- ((and first-rhs
+ ((and satured-first-rhs
(not first-parent-follow))
(setq
look-aheads
(parser-generator--merge-max-terminal-sets
- first-rhs
+ satured-first-rhs
nil)))
((and first-parent-follow
- (not first-rhs))
+ (not satured-first-rhs))
(setq
look-aheads
(parser-generator--merge-max-terminal-sets
nil
first-parent-follow)))
- ((and first-rhs
+ ((and satured-first-rhs
first-parent-follow)
(setq
look-aheads
(parser-generator--merge-max-terminal-sets
- first-rhs
+ satured-first-rhs
first-parent-follow)))
(t (error
"Unexpected empty FIRST for production: %S and parent-follow: %S"
production
parent-follow)))
+
(parser-generator--debug
(message "look-aheads: %S" look-aheads))
- ;; TODO merge-max-terminal-sets should do the right thing
;; For each non-terminal in the production right-hand side
;; push a new item to stack with a local-follow
diff --git a/parser-generator.el b/parser-generator.el
index 28be004d80..e956ffc033 100644
--- a/parser-generator.el
+++ b/parser-generator.el
@@ -2101,20 +2101,27 @@
(defun parser-generator-generate-sets-of-terminals (sets count)
"Generate set of terminals in sequence from SETS with COUNT."
- (let ((sets-of-terminals))
+ (let ((sets-of-terminals)
+ (terminal-set-exists-p (make-hash-table :test 'equal)))
(dolist (set sets)
(let ((item-count (length set))
(item-index 0)
(only-terminals t)
- (terminal-count 0))
+ (terminal-count 0)
+ (terminals))
(while (and
only-terminals
+ (< terminal-count count)
(< item-index item-count))
(let ((item (nth item-index set)))
(if (parser-generator--valid-terminal-p item)
- (setq
- terminal-count
- (1+ terminal-count))
+ (progn
+ (push
+ item
+ terminals)
+ (setq
+ terminal-count
+ (1+ terminal-count)))
(setq
only-terminals
nil)))
@@ -2123,9 +2130,17 @@
(1+ item-index)))
(when (and
only-terminals
- (= terminal-count count))
+ (= terminal-count count)
+ (not
+ (gethash
+ terminals
+ terminal-set-exists-p)))
+ (puthash
+ terminals
+ t
+ terminal-set-exists-p)
(push
- set
+ (reverse terminals)
sets-of-terminals))))
(reverse sets-of-terminals)))
diff --git a/test/parser-generator-test.el b/test/parser-generator-test.el
index e159585bf5..a7d415abc3 100644
--- a/test/parser-generator-test.el
+++ b/test/parser-generator-test.el
@@ -1085,20 +1085,19 @@
(parser-generator-set-grammar '((S A B) ("a" "b") ((S A) (S (B)) (B "a") (A
"a") (A ("b" "a"))) S))
(parser-generator-process-grammar)
- ;; TODO Test here
(should
(equal
(parser-generator-generate-sets-of-terminals
'(("a" "a") ("b") ("b" "a") ("a" "b" "a") ("a" e S "b" "a") ("b" "b" A))
2)
- '(("a" "a") ("b" "a"))))
+ '(("a" "a") ("b" "a") ("a" "b") ("b" "b"))))
(should
(equal
(parser-generator-generate-sets-of-terminals
'(("a" "a") ("b") ("b" "a") ("a" "b" "a") ("a" e S "b" "a") ("b" "b" A))
1)
- '(("b"))))
+ '(("a") ("b"))))
(should
(equal
@@ -1107,6 +1106,13 @@
3)
'(("a" "b" "a"))))
+ (should
+ (equal
+ (parser-generator-generate-sets-of-terminals
+ '(("a" e) ("b") ("b" "a") ("a" "b" "a") ("a" e S "b" "a") ("b" "b" A))
+ 1)
+ '(("a") ("b"))))
+
(message "Passed tests for (parser-generator--generate-sets-of-terminals)"))
(defun parser-generator-test--generate-terminal-saturated-first-set ()
@@ -1121,12 +1127,13 @@
(equal
(parser-generator-generate-terminal-saturated-first-set
'(("a" "b") ("a" "a" e) ("b") ("a" e)))
- '(("a" "b"))))
+ '(("a" "b") ("a" "a"))))
+
(should
(equal
(parser-generator-generate-terminal-saturated-first-set
'(("a" "b") ("a" "a" e) ("b" "b") ("a" e)))
- '(("a" "b") ("b" "b"))))
+ '(("a" "b") ("a" "a") ("b" "b"))))
(message "Passed tests for
(parser-generator-generate-terminal-saturated-first-set)"))
- [elpa] externals/parser-generator a046c8584d 73/82: Started on documentation for LL(k) and LL(1), (continued)
- [elpa] externals/parser-generator a046c8584d 73/82: Started on documentation for LL(k) and LL(1), Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator f07939a440 76/82: Added example from Wikipedia and passing test, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 03a11c4369 14/82: Started test for LL(k) parser-table generation, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 9d6ca94d0e 02/82: More work on LL(k) parser, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 6ce0dd9429 04/82: Improved function to calculate merge max terminal sets, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 52734d7160 16/82: Updated TODO items, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 7b77032f71 22/82: Parser table generation for LLk now works for productions, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator fe728f8ad8 23/82: Passing test for generating LLk parser table, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 3b9977b51b 28/82: More work on LLk test, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator f23bc217d8 30/82: More wrestling, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 6e91a4b498 32/82: More work on helper functions,
Christian Johansson <=
- [elpa] externals/parser-generator 80dd506b65 33/82: More work on LL-helper functions, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator e6f9ac545f 37/82: Cleanup after byte-compilation, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator cf4332ef0e 40/82: Started on LLk parsing algorithm, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator f5f7b2c82b 41/82: Added TODO items, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 2e76c4b57e 42/82: Added TODO items, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 8f9e4d4537 46/82: Passing 2 parse examples with k=2, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator fe0decba88 50/82: Passed one test for LLk where k=1, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 72bbadddc0 51/82: Added TODO items, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 2e2496d51f 54/82: Added notes, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 2598402cc7 56/82: Added TODO item, Christian Johansson, 2022/05/12