[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/parser-generator 4c75f65 101/434: Added TODO items
From: |
ELPA Syncer |
Subject: |
[elpa] externals/parser-generator 4c75f65 101/434: Added TODO items |
Date: |
Mon, 29 Nov 2021 15:59:17 -0500 (EST) |
branch: externals/parser-generator
commit 4c75f65e79833a98631eb9169674fd08db0b3fe4
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Added TODO items
---
parser-lr.el | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 63 insertions(+), 9 deletions(-)
diff --git a/parser-lr.el b/parser-lr.el
index ac85404..8b82297 100644
--- a/parser-lr.el
+++ b/parser-lr.el
@@ -42,19 +42,73 @@
(defun parser-lr--generate-action-tables ()
"Generate action-tables for lr-grammar."
(unless parser-lr--action-tables
- (let ((action-tables nil))
+ (let ((action-tables nil)
+ (states '(shift reduce accept error)))
(dolist (goto-table parser-lr--goto-tables)
;; (message "goto-table: %s" goto-table)
(let ((goto-index (car goto-table))
- (gotos (car (cdr goto-table))))
+ (gotos (car (cdr goto-table)))
+ (found-action nil))
(let ((lr-items (gethash goto-index parser-lr--items)))
- (dolist (lr-item lr-items)
- ;; TODO Iterate all possible
- ;; TODO (a) f(u) = shift if [A -> B . C, v] is in LR-items, C !=
e and u is in EFF(Cv)
- ;; TODO (b) f(u) = reduce i if [A -> B ., u] is in a and A -> B
is product i in P, i > 1
- ;; TODO (c) f(e) = accept if [S' -> S ., e] is in a
- ;; TODO (d) f(u) = error otherwise
- ))))
+ (let ((lr-items-length (length lr-items)))
+ ;; TODO Where u is in (T U e)*k
+ (dolist (state states)
+ (let ((state-in-progress t)
+ (lr-item)
+ (lr-item-index 0))
+ (while (and
+ state-in-progress
+ (< lr-item-index lr-items-lengths))
+ (setq lr-item (nth lr-item-index lr-items))
+ (message "lr-item: %s" lr-item)
+ (cond
+
+ ((eq state 'shift)
+ ;; TODO (a) f(u) = shift if [A -> B . C, v] is in
LR-items, C != e and u is in EFF(Cv)
+ (when (nth 2 lr-item)
+ (let ((C (nth 2 lr-item))
+ (v nth 3 lr-item))
+ (message "C: %s" C)
+ (message "v: %s" v)
+ (let ((Cv (append C v)))
+ (message "Cv: %s" Cv)
+ (when Cv
+ (let ((eff (parser--e-free-first Cv)))
+ (message "eff: %s" eff)
+ (when eff
+ ;; TODO Go through eff-items and see if any
item is a valid look-ahead of grammar
+ ;; in that case save in action table a shift
action here
+ (setq found-action t)
+ (setq state-in-progress nil))))))))
+
+ ((eq state 'reduce)
+ ;; (b) f(u) = reduce i if [A -> B ., u] is in a and A ->
B is production i in P, i > 1
+ (unless (nth 2 lr-item)
+ (let ((u (nth 3 lr-item)))
+ (when (parser--valid-look-ahead-p u)
+ ;; TODO Determine production number
+ ;; save reduction action in action table
+ (setq found-action t)
+ (setq state-in-progress nil)))))
+
+ ((eq state 'accept)
+ ;; TODO (c) f(e) = accept if [S' -> S ., e] is in a
+ (when (and
+ (not (nth 2 lr-item))
+ (eq (nth 3 lr-item) `(,parser--e-identifier)))
+ ;; TODO Save in action table accept action for e
+ (setq found-action t)
+ (setq state-in-progress nil)))
+
+ ((eq state 'error)
+ (if found-action
+ (setq state-in-progress nil)
+ ;; TODO Save error action here?
+ ;; TODO (d) f(u) = error otherwise
+ ))
+
+ )
+ (setq lr-item-index (1+ lr-item-index)))))))))
(setq parser-lr--action-table action-tables))))
;; Algorithm 5.9, p. 389
- [elpa] externals/parser-generator f8f5fe2 046/434: Started on function to calculate lk-items for a viable prefix, (continued)
- [elpa] externals/parser-generator f8f5fe2 046/434: Started on function to calculate lk-items for a viable prefix, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 8d0a93e 053/434: More work on algorithm, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 6d2e231 059/434: Added two more failing valid LR-set calculation tests, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 15dc472 067/434: Added TODO items, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 44eb5a3 062/434: Passing unit test for V(e) and V(S), ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator a7d1cc0 070/434: Updated README, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 3373881 085/434: More work on GOTO-table generation, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 5957fad 076/434: First implementation of generating LR-items for grammar, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 7689ec5 086/434: More work, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator c992a54 093/434: Added info in README.md about LR-items, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 4c75f65 101/434: Added TODO items,
ELPA Syncer <=
- [elpa] externals/parser-generator 6ee548e 005/434: Updated README, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 5150b91 075/434: Started working on lr-items for grammar function, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 59aea4d 077/434: More tweaking new algorithm, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator d0c9663 082/434: Passing test for distinct LR-items for grammar, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 7a48197 084/434: Removed obsolete variable, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 7fe7318 087/434: Passed test for distinct LR-items for grammar, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator ba95bff 094/434: Started on new algorithm, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 6f524ed 108/434: Various stuff, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 79c06fd 113/434: Added error signal if no parser action or LR-item set is found, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator daf93e0 097/434: Added failing unit test for action tables generation, ELPA Syncer, 2021/11/29