[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/parser-generator a2a629c16d 18/82: More work on data st
From: |
Christian Johansson |
Subject: |
[elpa] externals/parser-generator a2a629c16d 18/82: More work on data structure for LL-tables |
Date: |
Thu, 12 May 2022 13:28:14 -0400 (EDT) |
branch: externals/parser-generator
commit a2a629c16d589f94195a18bc3e16bb2ef0d17fab
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
More work on data structure for LL-tables
---
parser-generator-ll.el | 68 +++++++++++++++++++---------------------
test/parser-generator-ll-test.el | 32 ++++++++++++++-----
2 files changed, 58 insertions(+), 42 deletions(-)
diff --git a/parser-generator-ll.el b/parser-generator-ll.el
index 8bf2e6c7fd..4ccc6ca159 100644
--- a/parser-generator-ll.el
+++ b/parser-generator-ll.el
@@ -46,8 +46,6 @@
"Construction of LL(k)-tables. Output the set of LL(k) tables needed to
construct a parsing table for the grammar G."
(let ((tables (make-hash-table :test 'equal))
- (table-count 0)
- (distinct-table-number (make-hash-table :test 'equal))
(distinct-item-p (make-hash-table :test 'equal))
(stack)
(stack-item)
@@ -128,10 +126,20 @@
(parser-generator--get-grammar-rhs
sub-symbol)))
(parser-generator--debug
- (message "\nfollow-set: %S for %S in %S" follow-set (nth
sub-symbol-index production-rhs) production-rhs)
- (message "merged-follow: %S" follow-set)
- (message "local-follow-set: %S" local-follow-set)
- (message "sub-symbol-rhss: %S" sub-symbol-rhss))
+ (message
+ "\nfollow-set: %S for %S in %S"
+ follow-set
+ (nth sub-symbol-index production-rhs)
+ production-rhs)
+ (message
+ "merged-follow: %S"
+ follow-set)
+ (message
+ "local-follow-set: %S"
+ local-follow-set)
+ (message
+ "sub-symbol-rhss: %S"
+ sub-symbol-rhss))
(dolist (local-follow local-follow-set)
(dolist (sub-symbol-rhs sub-symbol-rhss)
(let* ((sub-symbol-production
@@ -156,8 +164,6 @@
(dolist (look-ahead look-aheads)
(let ((table
(list
- production-lhs
- parent-follow
look-ahead
production-rhs))
(item-hash-key
@@ -167,39 +173,32 @@
parent-follow
look-ahead))
(table-hash-key
- (format
- "%S-%S"
+ (list
production-lhs
parent-follow)))
+
+ ;; Only add distinct items
(unless (gethash item-hash-key distinct-item-p)
(puthash
item-hash-key
t
distinct-item-p)
- (let ((existing-table-number
- (gethash
- table-hash-key
- distinct-table-number)))
- (if existing-table-number
- (puthash
- existing-table-number
- (push
- table
- (gethash
- existing-table-number
- tables))
- tables)
- (puthash
+ (if (gethash
table-hash-key
- table-count
- distinct-table-number)
+ tables)
(puthash
- table-count
- (list table)
+ table-hash-key
+ (push
+ table
+ (gethash
+ table-hash-key
+ tables))
tables)
- (setq
- table-count
- (1+ table-count))))))))
+ (puthash
+ table-hash-key
+ (list table)
+ tables)
+ )))))
(parser-generator--debug
(message "\nproduction-lhs: %S" production-lhs)
@@ -209,16 +208,15 @@
(message "first-parent-follow: %S" first-parent-follow)
(message "look-aheads: %S" look-aheads))))
+ ;; TODO Add deterministic sorting here
(let ((sorted-tables))
(maphash
(lambda (k v)
(push
- (list k (sort v 'parser-generator--sort-list))
+ (list k v)
sorted-tables))
tables)
- (sort
- (reverse sorted-tables)
- (lambda (a b) (< (car a) (car b)))))))
+ sorted-tables)))
;; TODO
diff --git a/test/parser-generator-ll-test.el b/test/parser-generator-ll-test.el
index d908336717..561b5ad7cc 100644
--- a/test/parser-generator-ll-test.el
+++ b/test/parser-generator-ll-test.el
@@ -33,17 +33,35 @@
)
(parser-generator-process-grammar)
(let ((tables (parser-generator-ll--generate-tables)))
- ;; (message "tables: %S" tables)
+ (message "tables: %S" tables)
(should
(equal
tables
'(
- (0 (((S) nil (a b) (a A a a)) ((S) nil (a a) (a A a a)) ((S) nil (b b)
(b A b a))))
- (1 (((A) (a a) (a a) (e)) ((A) (a a) (b a) (b))))
- (2 (((A) (b a) (b b) (b)) ((A) (b a) (b a) (e))))
+ (
+ ((S) nil)
+ (
+ ((a b) (a A a a))
+ ((a a) (a A a a))
+ ((b b) (b A b a))
+ )
+ )
+ (
+ ((A) (a a))
+ (
+ ((a a) (e))
+ ((b a) (b))
+ )
+ )
+ (
+ ((A) (b a))
+ (
+ ((b b) (b))
+ ((b a) (e))
+ )
+ )
)))
- tables
- )
+ tables)
(message "Passed tests for (parser-generator-ll--generate-tables)"))
@@ -64,7 +82,7 @@
tables)))
(message "parser-tables: %S" parser-tables)
- ;; TODO Add test here
+ ;; TODO Make this pass
(should
(equal
'(
- [elpa] externals/parser-generator 89105668e8 01/82: Started on LL(k) implementation, (continued)
- [elpa] externals/parser-generator 89105668e8 01/82: Started on LL(k) implementation, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 878b2900f2 05/82: Improved calculation of merged max terminals when one of the set is undefined, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator d397a1d48e 12/82: Improved variable naming, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator b09b22c0be 13/82: Passing test for LL(k) table Example 5.15, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 7c10be74b8 06/82: Added TODO items, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 1d1e4e4bf8 03/82: More work on LL(k) parser, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 4cb0a0b941 08/82: More work on LL table generation, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 29bad0440f 09/82: More work on LL table generation, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 87435188dd 15/82: Added function to set EOF-identifier, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator bab123bdda 17/82: Added reference to PHP 8.1, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator a2a629c16d 18/82: More work on data structure for LL-tables,
Christian Johansson <=
- [elpa] externals/parser-generator 542a50d9c1 20/82: Remove usage of a hash-table, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 221446d647 24/82: Started implementation of LLk validation, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator ab4ce4d668 25/82: Tests for validating LLk grammar passing, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 04eb4d066c 27/82: Started on test for Example 5.17, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 5c0bcd5f9a 36/82: Passing test for LL-table generation example 5.17, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 1290048b84 39/82: Improved documentation, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 57c6fdda2f 43/82: Passing test for generating LL-parser hash-table, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator b37ba1eddf 52/82: Created TODO item, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator af3740c46a 59/82: More refactoring, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 3d373f4dfa 60/82: Updated docs, Christian Johansson, 2022/05/12