[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/parser-generator e02d5d7 049/434: More work on calculat
From: |
ELPA Syncer |
Subject: |
[elpa] externals/parser-generator e02d5d7 049/434: More work on calculating valid LR-items |
Date: |
Mon, 29 Nov 2021 15:59:06 -0500 (EST) |
branch: externals/parser-generator
commit e02d5d7e15ee6728ace2feccb7c9f24eb7ca9702
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
More work on calculating valid LR-items
---
parser.el | 56 +++++++++++++++++++++-----------------------------------
1 file changed, 21 insertions(+), 35 deletions(-)
diff --git a/parser.el b/parser.el
index 8e9c978..a9a4315 100644
--- a/parser.el
+++ b/parser.el
@@ -73,10 +73,6 @@
(error "No grammar G defined!")))
(nth 0 G))
-(defun parser--get-grammar-rhs (lhs)
- "Return right hand sides of LHS if there is any."
- (gethash lhs parser--table-productions))
-
(defun parser--get-grammar-productions (&optional G)
"Return productions of grammar G."
(unless G
@@ -85,6 +81,10 @@
(error "No grammar G defined!")))
(nth 2 G))
+(defun parser--get-grammar-rhs (lhs)
+ "Return right hand sides of LHS if there is any."
+ (gethash lhs parser--table-productions))
+
(defun parser--get-grammar-start (&optional G)
"Return start of grammar G."
(unless G
@@ -639,7 +639,6 @@
(defun parser--lr-items (γ)
"Calculate valid LR-items for the viable prefix Γ."
(let ((lr-items (make-hash-table :test 'equal))
- (productions (parser--get-grammar-productions))
(start (parser--get-grammar-start)))
(unless (listp γ)
(setq γ (list γ)))
@@ -651,23 +650,15 @@
;; 1
;; Iterate all productions in grammar
- (let ((lr-items-e))
+ (let ((lr-items-e)
+ (start-productions (parser--get-grammar-rhs start)))
;; a
- (dolist (p productions)
- (let ((production-lhs (car p)))
- ;; For all productions of the form S -> . α
- (when (eq production-lhs start)
- (let ((production-rhs (cdr p)))
- (dolist (rhs production-rhs)
-
- ;; Make sure RHS is a list
- (unless (listp rhs)
- (setq rhs (list rhs)))
-
- ;; Add [S -> . α] to V(e)
- (push `(,production-lhs nil ,rhs e) lr-items-e)
- (puthash `(e ,production-lhs nil ,rhs e) t
lr-item-exists))))))
+ (dolist (production-rhs start-productions)
+ (dolist (rhs production-rhs)
+ ;; Add [S -> . α] to V(e)
+ (push `(,start nil ,rhs e) lr-items-e)
+ (puthash `(e ,start nil ,rhs e) t lr-item-exists)))
;; b, c
;; 1.b. iterate every item in v-set(e), if [A -> . Bα, u] is an item
and B -> β is in P
@@ -694,25 +685,20 @@
(let ((rhs-rest (append (cdr rhs) suffix)))
(let ((rhs-first (parser--first rhs-rest)))
(message "FIRST(%s) = %s" rhs-rest rhs-first)
+ (let ((sub-production (parser--get-grammar-rhs
rhs-first)))
- ;; For each production with B as LHS
- (dolist (p productions)
- (let ((sub-lhs (car p)))
- (when (eq sub-lhs lhs)
- (let ((sub-rhs (cdr p)))
- (unless (listp sub-rhs)
- (setq sub-rhs (list sub-rhs)))
+ ;; For each production with B as LHS
+ (dolist (sub-rhs sub-production)
- ;; For each x in FIRST(αu) add [B -> . β, x]
to v-set(e)
- (dolist (f rhs-first)
- ;; Provided it is not already there
- (unless (gethash `(e ,lhs nil ,sub-rhs ,f)
lr-item-exists)
- (push `(,lhs nil ,sub-rhs ,f) lr-items-e)
- (setq found-new t))))))))))))))))
+ ;; For each x in FIRST(αu)
+ (dolist (f rhs-first)
+ ;; Add [B -> . β, x] to v-set(e), provided it
is not already there
+ (unless (gethash `(e ,rhs-first nil ,sub-rhs
,f) lr-item-exists)
+ (push `(,rhs-first nil ,sub-rhs ,f)
lr-items-e)
- ;; TODO 1.c. repeat b until no more items can be added to v-set(e)
- (puthash 'e lr-items-e lr-items))
+ ;; 1.c. repeat b until no more items can be
added to v-set(e)
+ (setq found-new t)))))))))))))))
;; 2
;; a
- [elpa] externals/parser-generator 58798c8 010/434: Starting on calculation of valid LK-sets for a valid grammar prefix, (continued)
- [elpa] externals/parser-generator 58798c8 010/434: Starting on calculation of valid LK-sets for a valid grammar prefix, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator f9c8348 008/434: Updated Travis and Makefil rule name, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 5f65cfc 015/434: More refactoring, using lists instead of string as grammar data type, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator f2791c1 022/434: Passed unit test 3 intermediate grammar, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 5d9b98c 011/434: Added functions to validate G and k and tests, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 356720c 030/434: Passing all unit tests using new data structure, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator e4fd795 007/434: Added compilation to test, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 42d92f1 014/434: More refactoring, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator f648b52 020/434: Passing first unit test for FIRST after new data-structure refactor, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator a4bbb2f 026/434: Using PDA algorithm for FIRST when β is above 1 symbol, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator e02d5d7 049/434: More work on calculating valid LR-items,
ELPA Syncer <=
- [elpa] externals/parser-generator 0465b58 045/434: Improved commenting, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 85dde51 009/434: Added License and Travis build logos, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 7bc3b70 017/434: Updated tests to use new data structure, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator ab4b4db 021/434: Passed second FIRST test again, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 80cf73d 019/434: Passing tests for valid-grammar syntax, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator bbbdea3 034/434: More improvement of documentation, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 9d0d9e5 027/434: Various debugging, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator e644708 018/434: Improved validation of grammar syntax, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator fbb8cad 012/434: Starting a refactor, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 563cbdd 023/434: Passed FIRST tests for semi-complex grammar, ELPA Syncer, 2021/11/29