[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/parser-generator 6d323a4 120/434: Implemented reduce ac
From: |
ELPA Syncer |
Subject: |
[elpa] externals/parser-generator 6d323a4 120/434: Implemented reduce action of LR-parser algorithm |
Date: |
Mon, 29 Nov 2021 15:59:22 -0500 (EST) |
branch: externals/parser-generator
commit 6d323a426f2115389dc2d3294fa3f955425561c5
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Implemented reduce action of LR-parser algorithm
---
parser-lr.el | 62 +++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 51 insertions(+), 11 deletions(-)
diff --git a/parser-lr.el b/parser-lr.el
index 4d2fd69..80c0b06 100644
--- a/parser-lr.el
+++ b/parser-lr.el
@@ -517,11 +517,8 @@
(let ((table-index (car pushdown-list)))
(message "table-index: %s" table-index)
- (let ((action-table (car (cdr (nth table-index action-tables))))
- (goto-table (car (cdr (nth table-index goto-tables)))))
-
+ (let ((action-table (car (cdr (nth table-index action-tables)))))
(message "action-table: %s" action-table)
- (message "goto-table: %s" goto-table)
(let ((action-match nil)
(action-table-length (length action-table))
@@ -571,7 +568,7 @@
))
((eq (car action-match) 'reduce)
- ;; TODO (b) If f(u) = reduce i and production i is A -> a,
+ ;; (b) If f(u) = reduce i and production i is A -> a,
;; then 2|a| symbols are removed from the top of the pushdown
;; list, and production number i is placed in the output
;; buffer. A new table T' is then exposed as the top table
@@ -580,11 +577,54 @@
;; pushdown list. We place A and this new table on top of the
;; the pushdown list and return to step (1)
- (let ((production-index (car (cdr action-match))))
-
- ;; TODO Load production by index here
-
- ))
+ (let ((production-number (car (cdr action-match))))
+ (let ((production
(parser--get-grammar-production-by-number production-number)))
+ (let ((production-lhs (car production))
+ (production-rhs (car (cdr production))))
+ (message "production: %s, lhs: %s rhs: %s" production
production-lhs production-rhs)
+ (unless (equal production-rhs (list
parser--e-identifier))
+ (let ((pop-items (* 2 (length (cdr production))))
+ (popped-items 0))
+ (message "Should pop %s items" pop-items)
+ (while (< popped-items pop-items)
+ (pop pushdown-list)
+ (setq popped-items (1+ popped-items)))))
+ (message "pushdown-list: %s" pushdown-list)
+ (push production-number output)
+
+ (let ((new-table-index (car pushdown-list)))
+ (message "new-table-index: %s" new-table-index)
+ (let ((goto-table (car (cdr (nth new-table-index
goto-tables)))))
+ (message "goto-table: %s" goto-table)
+ (let ((goto-table-length (length goto-table))
+ (goto-index 0)
+ (searching-match t)
+ (next-index))
+
+ (while (and
+ searching-match
+ (< goto-index goto-table-length))
+ (let ((goto-item (nth goto-index goto-table)))
+ (let ((goto-item-look-ahead (car goto-item))
+ (goto-item-next-index (car (cdr
goto-item))))
+ (message "goto-item-look-ahead: %s"
goto-item-look-ahead)
+ (message "goto-item-next-index: %s"
goto-item-next-index)
+
+ (when (equal goto-item-look-ahead
production-lhs)
+ (setq next-index goto-item-next-index)
+ (setq searching-match nil))))
+
+ (setq goto-index (1+ goto-index)))
+
+ (unless next-index
+ (error (format
+ "Found no goto-item for %s in index %s"
+ production-lhs
+ table-index)))
+
+ (push production-lhs pushdown-list)
+ (push next-index pushdown-list)
+ (message "Performed reduction, new pushdownlist:
%s" pushdown-list))))))))
((eq action-match '(accept))
;; (d) If f(u) = accept, we halt and declare the string
@@ -594,7 +634,7 @@
(setq accept t))
)))))))
- output))
+ (nreverse output)))
(provide 'parser-lr)
- [elpa] externals/parser-generator 8cda060 149/434: Made some functions public, (continued)
- [elpa] externals/parser-generator 8cda060 149/434: Made some functions public, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator c1d3707 150/434: Passing test for including SDT in Produductions, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator d36051c 103/434: Parser now creates hash table over productions to their production number, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator e3d3007 109/434: Tweaking of action-table generation for canonical LR-parser, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator d7daabf 111/434: Fixed bug with e-free-first function, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 2be434c 114/434: Removed obsolete debug messages, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 89d128c 123/434: Added TODO item, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 044f33a 151/434: Added more support for SDT, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 96f128f 155/434: More various stuff, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator a586a0e 162/434: More work on incremental parsing, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 6d323a4 120/434: Implemented reduce action of LR-parser algorithm,
ELPA Syncer <=
- [elpa] externals/parser-generator 9b44827 124/434: Optimized LR-parser with hash-tables, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 01fc56f 127/434: Updated list of grammars, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 4ef0430 133/434: White-space fix, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator b2fd896 136/434: Added support for indexed tokens, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 4746c64 137/434: Updated example for LR parse with indexed tokens, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 04a3ec5 141/434: Added separate file for syntax analysis, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 71e4eaa 145/434: Merge branch 'master' of git.cvj.se:/home/git/emacs-parser-generator, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 173fe94 152/434: Preparations for translation, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator be557ba 013/434: More work on refactor, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator fdbdff7 157/434: Added unit test for SDT in LR-parser, ELPA Syncer, 2021/11/29