branch: externals/parser-generator commit 0d6d46d69a7c2fcffd5eefe402c89e4b1dc661dd Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Debugging incremental issue with exported translator --- parser-generator-lr.el | 31 +++++++++++++++++-------- test/parser-generator-lr-export-test.el | 41 ++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/parser-generator-lr.el b/parser-generator-lr.el index 8e23c9b..1b625f4 100644 --- a/parser-generator-lr.el +++ b/parser-generator-lr.el @@ -954,16 +954,27 @@ (> parser-generator-lex-analyzer--index pre-index) - (push - `(,parser-generator-lex-analyzer--index - ,pushdown-list - ,output - ,translation - ,translation-symbol-table) - history) - (setq - pre-index - parser-generator-lex-analyzer--index)) + ;; We make a copy of the hash-table here to avoid passing same + ;; hash-table every-time with pointer + (let ((translation-symbol-table-copy + (make-hash-table :test 'equal))) + (maphash + (lambda (key value) + (puthash + key + value + translation-symbol-table-copy)) + translation-symbol-table) + (push + `(,parser-generator-lex-analyzer--index + ,pushdown-list + ,output + ,translation + ,translation-symbol-table-copy) + history) + (setq + pre-index + parser-generator-lex-analyzer--index))) ;; (1) The look-ahead string u, consisting of the next k input symbols, is determined. (let ((look-ahead diff --git a/test/parser-generator-lr-export-test.el b/test/parser-generator-lr-export-test.el index 487c4e8..11b644c 100644 --- a/test/parser-generator-lr-export-test.el +++ b/test/parser-generator-lr-export-test.el @@ -44,33 +44,43 @@ (should (equal + '(2 2 2 1 1) + (parser-generator-lr-parse))) + (should + (equal "bbaaba" (parser-generator-lr-translate))) ;; Export parser - (let ((export (parser-generator-lr-export-to-elisp "fa"))) + (let ((export (parser-generator-lr-export-to-elisp "ba"))) + (message "export:\n%s\n" export) (with-temp-buffer (insert export) (eval-buffer) (should (equal t - (fboundp 'fa-translate)))) + (fboundp 'ba-translate)))) - (when (fboundp 'fa-translate) + (when (fboundp 'pa-translate) + (should + (equal + '(2 2 2 1 1) + (ba-parse)))) + + (when (fboundp 'ba-translate) (should (equal "bbaaba" - (fa-translate)))))) + (ba-translate)))))) (should (equal t - (fboundp 'fa--parse))) + (fboundp 'ba--parse))) - (when (fboundp 'fa--parse) - (let ((regular-parse (fa--parse))) - ;; (message "regular-parse: %s" regular-parse) + (when (fboundp 'ba--parse) + (let ((regular-parse (ba--parse))) (let ((regular-parse-history (nth 3 regular-parse))) ;; (message "regular-parse-history: %s" regular-parse-history) (let ((history-length (length regular-parse-history)) @@ -86,14 +96,17 @@ (translation-symbol-table (nth 4 history)) (history-list iterated-history)) - ;; (message "input-tape-index: %s" input-tape-index) - ;; (message "pushdown-list: %s" pushdown-list) - ;; (message "output: %s" output) - ;; (message "translation: %s" translation) - ;; (message "history-list: %s" history-list) + (message "\nIncremental %s" history-index) + (message "regular-parse: %s" regular-parse) + (message "input-tape-index: %s" input-tape-index) + (message "pushdown-list: %s" pushdown-list) + (message "output: %s" output) + (message "translation: %s" translation) + (message "translation-symbol-table: %s" translation-symbol-table) + (message "history-list: %s\n" history-list) (let ((incremental-parse - (fa--parse + (ba--parse input-tape-index pushdown-list output