[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)
- [elpa] externals/parser-generator fe728f8ad8 23/82: Passing test for generating LLk parser table, (continued)
- [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, 2022/05/12
- [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 <=
- [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
- [elpa] externals/parser-generator 7f3c384b6d 55/82: Passing more LLk tests, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 0856bb7784 58/82: Started on refactor were k=1 will be treated with different algorithm, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 2181545d26 64/82: Implemented test for validation of LL(1) grammar, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 4051737aeb 65/82: Added TODO item for LL(k) translation, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 08af836006 69/82: More work on SDT for LL grammar, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 7d87a2d154 79/82: Implemented exported LL(k) and LL(1) parser, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 75323b10e5 81/82: Merge branch 'feature/llk-parser', Christian Johansson, 2022/05/12