[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/parser-generator b040d9b 357/434: Tests for infix calcu
From: |
ELPA Syncer |
Subject: |
[elpa] externals/parser-generator b040d9b 357/434: Tests for infix calculator working |
Date: |
Mon, 29 Nov 2021 16:00:15 -0500 (EST) |
branch: externals/parser-generator
commit b040d9b521facd990c01df38e50b5fca6ae38663
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Tests for infix calculator working
---
parser-generator-lr.el | 43 +++++++++++++++++++---------------------
parser-generator.el | 6 ++++--
test/parser-generator-lr-test.el | 18 ++++++++++-------
3 files changed, 35 insertions(+), 32 deletions(-)
diff --git a/parser-generator-lr.el b/parser-generator-lr.el
index b84b914..8c74a52 100644
--- a/parser-generator-lr.el
+++ b/parser-generator-lr.el
@@ -653,16 +653,10 @@
(dolist (lr-item lr-items)
(let ((symbols (nth 2 lr-item)))
(when symbols
+ ;; Convert symbols in grammar with attributes to simple symbols
(let ((next-symbol
- (car symbols)))
-
- ;; Convert symbols with attributes to simple symbols
- (when
- (listp next-symbol)
- (setq
- next-symbol
- (car next-symbol)))
-
+ (parser-generator--get-symbol-without-attributes
+ (car symbols))))
(let ((temp-hash-key
(format
"%S"
@@ -1335,15 +1329,11 @@
lr-item-suffix-rest
(cdr lr-item-suffix))
- ;; Remove potential attributes from symbol for comparison
- (if
- (listp lr-item-suffix-first)
- (setq
- lr-item-suffix-first-wo-attributes
- (car lr-item-suffix-first))
- (setq
- lr-item-suffix-first-wo-attributes
- lr-item-suffix-first))
+ ;; NOTE x is always without attributes
+ (setq
+ lr-item-suffix-first-wo-attributes
+ (parser-generator--get-symbol-without-attributes
+ lr-item-suffix-first))
(parser-generator--debug
(message "lr-item: %s" lr-item)
@@ -1364,7 +1354,8 @@
(let ((combined-prefix
(append
lr-item-prefix
- (list lr-item-suffix-first))))
+ (list
+ lr-item-suffix-first))))
(let ((lr-new-item-1))
(if
(=
@@ -1397,9 +1388,9 @@
(while added-new
(setq added-new nil)
- ;; TODO Use caches to optimize this loop?
(dolist (lr-item lr-new-item)
- (let ((lr-item-suffix (nth 2 lr-item)))
+ (let ((lr-item-suffix
+ (nth 2 lr-item)))
(let ((lr-item-suffix-first
(car lr-item-suffix))
(lr-item-suffix-rest
@@ -1408,6 +1399,10 @@
(nth 3 lr-item))))
(parser-generator--debug
(message
+ "lr-item-suffix-first: %s from %s"
+ lr-item-suffix-first
+ lr-item-suffix)
+ (message
"lr-item-suffix-rest: %s from %s + %s"
lr-item-suffix-rest
(cdr lr-item-suffix)
@@ -1416,8 +1411,10 @@
;; (b) If [A -> a . Bb, u] has been placed in V(X1,...,Xi)
;; and B -> D is in P
(when
- (parser-generator--valid-non-terminal-p
- lr-item-suffix-first)
+ (and
+ lr-item-suffix-first
+ (parser-generator--valid-non-terminal-p
+ lr-item-suffix-first))
(let ((lr-item-suffix-rest-first
(parser-generator--first
diff --git a/parser-generator.el b/parser-generator.el
index befa2ca..eea8285 100644
--- a/parser-generator.el
+++ b/parser-generator.el
@@ -17,7 +17,7 @@
(defvar
parser-generator--debug
- t
+ nil
"Whether to print debug messages or not.")
(defvar
@@ -849,7 +849,9 @@
(setq
valid-attribute
nil))
- (setq symbol (car symbol)))
+ (setq
+ symbol
+ (car symbol)))
(and
valid-attribute
(gethash
diff --git a/test/parser-generator-lr-test.el b/test/parser-generator-lr-test.el
index f8e4848..013e3c1 100644
--- a/test/parser-generator-lr-test.el
+++ b/test/parser-generator-lr-test.el
@@ -791,18 +791,13 @@
(exp "-" exp (lambda(args) (- (nth 0 args) (nth 2 args))))
(exp "*" exp (lambda(args) (* (nth 0 args) (nth 2 args))))
(exp "/" exp (lambda(args) (/ (nth 0 args) (nth 2 args))))
- ("-" (exp (%prec NEG)) (lambda(args) (- (nth 1 args))))
+ ("-" exp (lambda(args) (- (nth 1 args))))
(exp "^" exp (lambda(args) (expt (nth 0 args) (nth 2 args))))
("(" exp ")" (lambda(args) (nth 1 args)))))
start))
(parser-generator-process-grammar)
- ;; TODO What we want is that after - exp there is a reduce action
- (let ((lr-item-sets (parser-generator-lr-generate-parser-tables)))
- (message "")
- (message "RAMBO: %S" lr-item-sets)
- (message ""))
-
+ (parser-generator-lr-generate-parser-tables)
(let ((buffer (generate-new-buffer "*buffer*")))
(switch-to-buffer buffer)
@@ -841,6 +836,15 @@
(parser-generator-lr-translate)))
(message "Passed -33+5 with correct result")
+ (switch-to-buffer buffer)
+ (kill-region (point-min) (point-max))
+ (insert "-33-3\n")
+ (should
+ (equal
+ -36
+ (parser-generator-lr-translate)))
+ (message "Passed -33-3 with correct result")
+
(kill-buffer))
(message "Passed tests for (parser-generator-lr--parse)"))
- [elpa] externals/parser-generator 5f13406 319/434: More work on supporting LR-grammar with precedence attributes, (continued)
- [elpa] externals/parser-generator 5f13406 319/434: More work on supporting LR-grammar with precedence attributes, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 989e79e 331/434: More debugging, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 8092c58 334/434: Added global declaration to unit test, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 778b96f 335/434: More work on global precedence declaration, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 0523eeb 336/434: More work on global precedence, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 0aed7b0 339/434: More work on global precedence in LR(k) parser, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator b84ed5e 342/434: Fixed issue with infix calculator translation test, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator f449039 346/434: More debugging, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 34f95b3 351/434: More debugging infix calculator, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator bb82646 356/434: More debugging, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator b040d9b 357/434: Tests for infix calculator working,
ELPA Syncer <=
- [elpa] externals/parser-generator 4404424 367/434: Added test for parsing context-sensitive attributes, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 2ad866c 371/434: Context-sensitive attribute are now tested through specified comparison function, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 9d5df0e 375/434: More working on trying to get the Infix example working, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 8fb8676 376/434: More work on Infix math example, passing another test, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 32e2c15 024/434: Fixed bug with e-production, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 26bf153 037/434: Setting look-ahead-number is now separated from setting grammar, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator a54061c 055/434: Debugging of new algorithm, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 62d06a0 063/434: Passing unit test for V(Sa), ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 186d7bb 065/434: Renamed function lr-items to lr-items-for-prefix, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 9792eeb 069/434: Added TODO items, ELPA Syncer, 2021/11/29