[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/parser-generator f9223ea 400/434: Added a flag to use s
From: |
ELPA Syncer |
Subject: |
[elpa] externals/parser-generator f9223ea 400/434: Added a flag to use shift conflict resolution in cases were precedence is missing |
Date: |
Mon, 29 Nov 2021 16:00:24 -0500 (EST) |
branch: externals/parser-generator
commit f9223ead2045f9702e79b448035b13635082c259
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Added a flag to use shift conflict resolution in cases were precedence is
missing
---
parser-generator-lr.el | 126 +++++++++++++++++++++++++--------------
test/parser-generator-lr-test.el | 1 +
2 files changed, 81 insertions(+), 46 deletions(-)
diff --git a/parser-generator-lr.el b/parser-generator-lr.el
index 713d055..1947e25 100644
--- a/parser-generator-lr.el
+++ b/parser-generator-lr.el
@@ -69,6 +69,10 @@
nil
"Table of the precedence type of all production numbers.")
+(defvar
+ parser-generator-lr--allow-default-conflict-resolution
+ nil
+ "Whether to allow to resolve shift/reduce conflicts with shift in cases were
there is no precedence values.")
;; Main Algorithms
@@ -1135,46 +1139,67 @@
(when (equal
a-follow
b-suffix-follow-eff-item)
- (if
- ;; If it's the same following symbol but we have
- ;; any production-number we might be able to continue
- ;; if there are precedence rules
- (or
- a-production-number
- b-production-number)
- (progn
- (unless
- (or
- (parser-generator-lr--action-takes-precedence-p
- a-follow
- a-production-number
- b-production-number)
- (parser-generator-lr--action-takes-precedence-p
- b-follow
- b-production-number
- a-production-number))
- (when
- signal-on-false
- (error
- "Inconsistent grammar! '%S' (index: %d) conflicts
with '%S' (index: %d) with look-ahead '%S' in sets:\n%S"
- a
- a-index
- b
- b-index
- b-suffix-follow-eff-item
- lr-item-sets))
- (setq valid-p nil)))
- (when
- signal-on-false
- (error
- "Inconsistent grammar! '%S' (index: %d) conflicts with
'%S' (index: %d) with look-ahead '%S' in sets:\n%S"
- a
- a-index
- b
- b-index
- b-suffix-follow-eff-item
- lr-item-sets))
- (setq valid-p nil)))))
+
+ (let ((a-production-precedence-value)
+ (b-production-precedence-value)
+ (symbol-precedence-value
+ (parser-generator-lr--get-symbol-precedence-value
+ a-follow)))
+ ;; Check if either production has a precedence-value
+ (when a-production-number
+ (setq
+ a-production-precedence-value
+
(parser-generator-lr--get-production-number-precedence-value
+ a-production-number)))
+ (when b-production-number
+ (setq
+ b-production-precedence-value
+
(parser-generator-lr--get-production-number-precedence-value
+ b-production-number)))
+
+ (if
+ ;; If it's the same following symbol but we have
+ ;; any production-number we might be able to continue
+ ;; if there are precedence rules
+ (or
+ symbol-precedence-value
+ a-production-precedence-value
+ b-production-precedence-value)
+ (progn
+ (unless
+ (or
+ (parser-generator-lr--action-takes-precedence-p
+ a-follow
+ a-production-number
+ b-production-number)
+ (parser-generator-lr--action-takes-precedence-p
+ b-follow
+ b-production-number
+ a-production-number))
+ (when
+ signal-on-false
+ (error
+ "Inconsistent grammar after precedence
calculation! '%S' (index: %d) conflicts with '%S' (index: %d) with look-ahead
'%S' in sets:\n%S"
+ a
+ a-index
+ b
+ b-index
+ b-suffix-follow-eff-item
+ lr-item-sets))
+ (setq valid-p nil)))
+ (unless
+
parser-generator-lr--allow-default-conflict-resolution
+ (when
+ signal-on-false
+ (error
+ "Inconsistent grammar without precedence
calculation! '%S' (index: %d) conflicts with '%S' (index: %d) with look-ahead
'%S' in sets:\n%S"
+ a
+ a-index
+ b
+ b-index
+ b-suffix-follow-eff-item
+ lr-item-sets))
+ (setq valid-p nil)))))))
(setq b-index (1+ b-index))))
(setq a-index (1+ a-index)))
(setq set-index (1+ set-index)))
@@ -1228,12 +1253,21 @@
b-precedence-value
b-production-precedence-value))))
- (funcall
- parser-generator-lr--precedence-comparison-function
- a-precedence-type
- a-precedence-value
- b-precedence-type
- b-precedence-value)))
+ ;; When precedence-values are lacking
+ ;; and default conflict resolution is enabled
+ ;; signal a shift action
+ (if
+ (and
+ (not a-precedence-value)
+ (not b-precedence-value)
+ parser-generator-lr--allow-default-conflict-resolution)
+ nil
+ (funcall
+ parser-generator-lr--precedence-comparison-function
+ a-precedence-type
+ a-precedence-value
+ b-precedence-type
+ b-precedence-value))))
;; Algorithm 5.8, p. 386
(defun parser-generator-lr--items-for-prefix (γ)
diff --git a/test/parser-generator-lr-test.el b/test/parser-generator-lr-test.el
index b09789e..ff5ef5a 100644
--- a/test/parser-generator-lr-test.el
+++ b/test/parser-generator-lr-test.el
@@ -856,6 +856,7 @@
(let ((table-lr-items (parser-generator-process-grammar)))
+ (parser-generator-lr-generate-parser-tables)
(should
(equal
- [elpa] externals/parser-generator 9c30f34 385/434: More work on refactoring conflict resolution, (continued)
- [elpa] externals/parser-generator 9c30f34 385/434: More work on refactoring conflict resolution, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 53fb785 395/434: Verified examples in documentation, added infix notation calculator example, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator e447145 402/434: Added notes about setting to allow default conflict resolution, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 201bcb1 405/434: Improved notes, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator aad1a17 404/434: Removed unnecessary logic in LR(0) action-table generation, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 1b2a150 403/434: Added failing test for e-identifier in the middle of a rule, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator aa8a2bf 391/434: Work on the tests for the exported lr-parser, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator a8c092d 386/434: More work on precedence logic, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 7a3e653 390/434: Added test for testing precedence of context-sensitive attribute, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 5cb63eb 399/434: Improve error message of invalid global declaration, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator f9223ea 400/434: Added a flag to use shift conflict resolution in cases were precedence is missing,
ELPA Syncer <=
- [elpa] externals/parser-generator ded7700 387/434: Added more test for infix precedence, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 9e8b89b 392/434: More work on exporting LR-parser, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator fc48311 409/434: Added test for FIRST calculation of multiple symbols and e-identifiers, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 6733b57 415/434: Added feature to move lex-analyzer forward, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 9eca533 410/434: Added test and implementation of calculating FIRST on multiple symbols were first is a non-terminal that expands into an e-identifier, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator ca21bcd 412/434: Shortened doc-string, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 0a3f5f5 426/434: Added test for LR(1) PHP 8.0 match grammar, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator c9906f7 420/434: Move order of export of LR lex-analyzer, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator a4c5d9f 429/434: Syntax-directed translations now have access to terminal data if any is available, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 428207c 432/434: Fixed bug with exported lr-parser with partial translation, ELPA Syncer, 2021/11/29