[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/parser-generator 6a4b353 344/434: More work on translat
From: |
ELPA Syncer |
Subject: |
[elpa] externals/parser-generator 6a4b353 344/434: More work on translations |
Date: |
Mon, 29 Nov 2021 16:00:12 -0500 (EST) |
branch: externals/parser-generator
commit 6a4b353e022d0ed96f0d1388a1f61a168a058985
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
More work on translations
---
parser-generator-lr.el | 54 +++++++++++++++++++++-------------------
parser-generator.el | 2 +-
test/parser-generator-lr-test.el | 35 ++++++++++++++++++--------
3 files changed, 53 insertions(+), 38 deletions(-)
diff --git a/parser-generator-lr.el b/parser-generator-lr.el
index 79373f4..67343e1 100644
--- a/parser-generator-lr.el
+++ b/parser-generator-lr.el
@@ -1798,8 +1798,7 @@
(setq popped-items (1+ popped-items)))))
(push production-number output)
- (let ((popped-items-meta-contents)
- (all-expanded t))
+ (let ((popped-items-meta-contents))
;; Collect arguments for translation
(dolist (popped-item popped-items-contents)
(parser-generator--debug
@@ -1826,15 +1825,19 @@
temp-hash-key
translation-symbol-table)
popped-items-meta-contents)
- (setq
- all-expanded
- nil)
(push
nil
popped-items-meta-contents)))))
- (setq
- popped-items-meta-contents
- (nreverse popped-items-meta-contents))
+
+ ;; If we just have one argument, pass it as a
scalar
+ (if (= (length popped-items-meta-contents) 1)
+ (setq
+ popped-items-meta-contents
+ (car popped-items-meta-contents))
+ (setq
+ popped-items-meta-contents
+ (nreverse popped-items-meta-contents)))
+
(parser-generator--debug
(message
"Production arguments: %s -> %s = %s"
@@ -1866,24 +1869,23 @@
translation
partial-translation))
- ;; When no translation is specified just use
arguments as translation
- (when all-expanded
- (let ((partial-translation
- popped-items-meta-contents))
- (parser-generator--debug
- (message
- "translation-symbol-table: %s = %s
(generic)"
- production-lhs
- partial-translation))
- (puthash
- (format
- "%S"
- production-lhs)
- partial-translation
- translation-symbol-table)
- (setq
- translation
- partial-translation)))))
+ ;; When no translation is specified just use
partial-translation as translation
+ (let ((partial-translation
+ popped-items-meta-contents))
+ (parser-generator--debug
+ (message
+ "translation-symbol-table: %s = %s (generic)"
+ production-lhs
+ partial-translation))
+ (puthash
+ (format
+ "%S"
+ production-lhs)
+ partial-translation
+ translation-symbol-table)
+ (setq
+ translation
+ partial-translation))))
(let ((new-table-index (car pushdown-list)))
(let ((goto-table-distinct-index
diff --git a/parser-generator.el b/parser-generator.el
index b3520c8..72a44da 100644
--- a/parser-generator.el
+++ b/parser-generator.el
@@ -17,7 +17,7 @@
(defvar
parser-generator--debug
- nil
+ t
"Whether to print debug messages or not.")
(defvar
diff --git a/test/parser-generator-lr-test.el b/test/parser-generator-lr-test.el
index b99a894..7da377a 100644
--- a/test/parser-generator-lr-test.el
+++ b/test/parser-generator-lr-test.el
@@ -573,7 +573,7 @@
(parser-generator-process-grammar)
;; (should-error
- ;; (parser-generator-lr-generate-parser-tables))
+ ;; (parser-generator-lr-generate-parser-tables))
(message "Infix calculator grammar caused expected error")
;; Add precedence to resolve conflicts
@@ -641,19 +641,19 @@
(start input)
(input
%empty
- (input line))
+ (input line (lambda(args) (nth 1 args))))
(line
"\n"
- (exp "\n"))
+ (exp "\n" (lambda(args) (nth 0 args))))
(exp
NUM
- (exp "+" exp (lambda(args) (+ (car (nth 0 args)) (car (nth 2 args)))))
- (exp "-" exp (lambda(args) (- (car (nth 0 args)) (car (nth 2 args)))))
- (exp "*" exp (lambda(args) (* (car (nth 0 args)) (car (nth 2 args)))))
- (exp "/" exp (lambda(args) (/ (car (nth 0 args)) (car (nth 2 args)))))
- ("-" (exp (%prec NEG)) (lambda(args) (- (car (nth 1 args)))))
- (exp "^" exp (lambda(args) (expt (car (nth 0 args)) (car (nth 2
args)))))
- ("(" exp ")" (lambda(args) (car (nth 1 args))))))
+ (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 "/" exp (lambda(args) (/ (nth 0 args) (nth 2 args))))
+ ("-" (exp (%prec NEG)) (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)
@@ -662,21 +662,34 @@
;; TODO Test functionality here (then move to translate test)
(let ((buffer (generate-new-buffer "*buffer*")))
+
(switch-to-buffer buffer)
(kill-region (point-min) (point-max))
(insert "5+5\n")
(should
(equal
10
- (car (parser-generator-lr-translate))))
+ (parser-generator-lr-translate)))
+ (message "5+5=10\n")
+
+ (switch-to-buffer buffer)
+ (kill-region (point-min) (point-max))
+ (insert "5+4\n")
+ (should
+ (equal
+ 9
+ (parser-generator-lr-translate)))
+ (message "5+4=9\n")
(switch-to-buffer buffer)
(kill-region (point-min) (point-max))
(insert "7-3\n")
+ (message "7-3=%S" (parser-generator-lr-translate))
(should
(equal
4
(parser-generator-lr-translate)))
+ (message "7-3=4\n")
(kill-buffer))
(message "Passed tests for (parser-generator-lr--parse)"))
- [elpa] externals/parser-generator 852f969 283/434: Merge branch 'master' of git.cvj.se:/home/git/emacs-parser-generator, (continued)
- [elpa] externals/parser-generator 852f969 283/434: Merge branch 'master' of git.cvj.se:/home/git/emacs-parser-generator, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 0d6d46d 294/434: Debugging incremental issue with exported translator, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator c4c68b2 302/434: Added progress-indicator to goto-table generation, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 586789d 308/434: Added cache to first calculation, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 236a124 322/434: More work on resolving conflicts, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 04c360b 318/434: LR-items set validation now supports symbols with attributes, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator ea02245 325/434: Improved debug output, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator e56bcff 324/434: Improved output of productions and action-tables, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator fb29641 337/434: Passing old context-sensitive precedence example with new structure, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 928b31d 343/434: More work on infix calculator, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 6a4b353 344/434: More work on translations,
ELPA Syncer <=
- [elpa] externals/parser-generator 85d1b49 345/434: Infix calculator translation passing some tests, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 08e9876 347/434: Fixed bug with associating a translation to multiple productions, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator c6d3ad2 352/434: Infix calculator working as expected without precedence rules, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 21948c8 358/434: Fixed lex-analyzer to infix calculator test to support white-space and floats, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 14711d4 363/434: Added more debug stuff, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator f0f2daa 364/434: Started refactor of context-sensitive attributes, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 7e1d2fb 368/434: Added TODO notes, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 5a1f09a 369/434: More work on adding support for production number related precedence, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator e4658d9 372/434: LR action-table generation is now using context-sensitive precedence resolution for reduce/reduce conflicts, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 6aff9d0 373/434: Made TODO notes, ELPA Syncer, 2021/11/29