[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/parser-generator e463bae 041/434: Passing tests for sor
From: |
ELPA Syncer |
Subject: |
[elpa] externals/parser-generator e463bae 041/434: Passing tests for sorting lists |
Date: |
Mon, 29 Nov 2021 15:59:04 -0500 (EST) |
branch: externals/parser-generator
commit e463baea4e60a8b257a73652d17672b4335e99f1
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Passing tests for sorting lists
---
parser.el | 21 ++++++---------------
test/parser-test.el | 10 +++++-----
2 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/parser.el b/parser.el
index 038378f..2d2dfa0 100644
--- a/parser.el
+++ b/parser.el
@@ -117,13 +117,13 @@
(defun parser--sort-list (a b)
"Return non-nil if a element in A is greater than a element in B in
lexicographic order."
- (let ((max-index (1- (min (length a) (length b))))
+ (let ((length (min (length a) (length b)))
(index 0)
(continue t)
(response nil))
(while (and
continue
- (< index max-index))
+ (< index length))
(let ((a-element (nth index a))
(b-element (nth index b)))
(if (string-greaterp a-element b-element)
@@ -428,7 +428,7 @@
(when (> (length
sub-rhs-leading-terminals) k)
(setq sub-rhs-leading-terminals
(butlast sub-rhs-leading-terminals (- (length sub-rhs-leading-terminals) k))))
(push `(,sub-rhs-leading-terminals
,alternative-all-leading-terminals-p ,(1+ input-tape-index)) stack))))
- (setq sub-terminal-index (1+
sub-terminal-index)))))
+ (setq sub-terminal-index (1+
sub-terminal-index)))))
(parser--debug (message "Sub-terminal-set: %s"
sub-terminal-set))
(when (or
@@ -562,22 +562,19 @@
(setq input-tape-index (1+ input-tape-index)))
(when (> first-length 0)
(push first first-list))))))
- (message "first-list-before-sort: %s" first-list)
(setq first-list (sort first-list 'parser--sort-list))
- (message "first-list-after-sort: %s" first-list)
first-list))))
;; Definition p. 343, FOLLOW(β) = w, w is the set {w|β=>*aβy and w is in
FIRST(y)}
(defun parser--follow (β)
- "Calculate follow-set of B."
+ "Calculate follow-set of Β."
;; Make sure argument is a list
(unless (listp β)
(setq β (list β)))
(let ((follow-set nil)
(match-length (length β)))
;; Iterate all productions in grammar
- (let ((productions (parser--get-grammar-productions))
- (k parser--look-ahead-number))
+ (let ((productions (parser--get-grammar-productions)))
(dolist (p productions)
;; Iterate all RHS of every production
(let ((production-rhs (cdr p))
@@ -600,19 +597,13 @@
(progn
(setq match-index (1+ match-index))
(when (= match-index match-length)
- (parser--debug
- (message "found full follow hit: %s" β))
(if (= rhs-index (1- rhs-count))
;; If rest of RHS is empty add e in follow-set
(push '(e) follow-set)
;; Otherwise add FOLLOW(rest) to follow-set
(let ((rest (nthcdr (1+ rhs-index) rhs)))
- (parser--debug
- (message "rest: %s" rest))
(let ((first-set (parser--first rest)))
- (parser--debug
- (message "rest-first-set: %s" first-set))
- (push first-set follow-set))))
+ (setq follow-set (append first-set
follow-set)))))
(setq match-index 0)))
(when (> match-index 0)
(setq match-index 0))))
diff --git a/test/parser-test.el b/test/parser-test.el
index e787e4c..1817fcd 100644
--- a/test/parser-test.el
+++ b/test/parser-test.el
@@ -152,7 +152,7 @@
(parser--set-look-ahead-number 1)
(should
(equal
- '(("d") ("c"))
+ '(("c") ("d"))
(parser--first 'S)))
(message "Passed first 1 with semi-complex grammar")
@@ -176,7 +176,7 @@
(parser--set-look-ahead-number 1)
(should
(equal
- '((a) (a) (c) (e))
+ '((a) (b) (c) (e))
(parser--first 'S)))
(message "Passed first 1 with complex grammar")
@@ -185,7 +185,7 @@
(parser--set-look-ahead-number 2)
(should
(equal
- '((a) (a c) (a b) (c a) (b a) (e) (c) (b) (c b))
+ '((a b) (a c) (a) (b a) (b) (c a) (c) (c b) (e))
(parser--first 'S)))
(message "Passed first 2 with complex grammar")
@@ -193,7 +193,7 @@
(parser--set-look-ahead-number 3)
(should
(equal
- '((a c b) (a) (a c) (a b) (c a) (c a c) (c a b) (b a) (b a c) (b a b) (c
b) (e) (c) (b) (c b a))
+ '((a) (a b) (a c) (a c b) (b a) (b a b) (b a c) (b) (c a) (c a b) (c a c)
(c b) (c) (c b a) (e))
(parser--first 'S)))
(message "Passed first 3 with complex grammar")
@@ -209,7 +209,7 @@
(parser--set-look-ahead-number 2)
(should
(equal
- '((c b) (c a))
+ '((c a) (c b))
(parser--e-free-first 'S)))
(message "Passed empty-free-first 2 with complex grammar")
- [elpa] externals/parser-generator 99aa5b6 350/434: Added more unit tests for calculator, (continued)
- [elpa] externals/parser-generator 99aa5b6 350/434: Added more unit tests for calculator, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator d8fb2da 354/434: Just white-space fixes, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 3964649 359/434: Added more failing unit tests, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 6e0e781 360/434: More debugging, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 2c262a4 362/434: Added new error when there is grammar conflict in action-table generation and no precedence comparison function is defined, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator a7a9506 366/434: Refactored structure of context-sensitive attributes, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 98ab0e4 377/434: More work on precedence logic in unit tests, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 1b8f025 016/434: More work on validating a grammar structure, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 1ae36fc 029/434: Added support for calculating first of a sentential form, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 38c2040 032/434: Improved markdown code examples, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator e463bae 041/434: Passing tests for sorting lists,
ELPA Syncer <=
- [elpa] externals/parser-generator 840c418 044/434: Improved comment about follow function, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 2a3a02d 083/434: Removed cache for LR-items for prefixes, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 3ba5250 090/434: Removed debugging stuff, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 83298fe 099/434: Passing test for function that generates possible look-ahead permutations, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator e9697ea 100/434: Added function that tests if a look-ahead is valid or not, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 53c09f7 119/434: Added hash-table for productions indexed by production-number, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 58e5806 129/434: Renamed plugin from parser to parser-generator, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 0695275 143/434: More updates to docs, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 1b17ef8 159/434: Added another unit tests for translations, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 04fdc96 167/434: Added unit-test for incremental translations, ELPA Syncer, 2021/11/29