[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/parser-generator f0f2daa 364/434: Started refactor of c
From: |
ELPA Syncer |
Subject: |
[elpa] externals/parser-generator f0f2daa 364/434: Started refactor of context-sensitive attributes |
Date: |
Mon, 29 Nov 2021 16:00:16 -0500 (EST) |
branch: externals/parser-generator
commit f0f2daa43b9b3ea6a553050c199e6573ac2d5803
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Started refactor of context-sensitive attributes
---
parser-generator.el | 92 +++++++++++++++++++++++++++--------------------------
1 file changed, 47 insertions(+), 45 deletions(-)
diff --git a/parser-generator.el b/parser-generator.el
index aa78b15..afd3767 100644
--- a/parser-generator.el
+++ b/parser-generator.el
@@ -110,6 +110,11 @@
nil
"Hash-table indexed by production-number and value is translation function.")
+(defvar
+ parser-generator--table-productions-attributes
+ nil
+ "Hash-table of attributes related to productions.")
+
;; Macros
@@ -407,7 +412,7 @@
t
parser-generator--table-non-terminal-p)))
- ;; Build hash-tables of attributes
+ ;; Build hash-tables of context-sensitive attributes
(setq
parser-generator--table-context-sensitive-attributes-p
(make-hash-table :test 'equal))
@@ -418,6 +423,8 @@
attribute
t
parser-generator--table-context-sensitive-attributes-p))
+
+ ;; Build hash-table of global attributes
(setq
parser-generator--table-global-attributes-p
(make-hash-table :test 'equal))
@@ -439,7 +446,7 @@
(parser-generator--valid-global-attribute-p
(car item))
(error
- "Invalid declaration '%S' in grammar!"
+ "Invalid global declaration '%S' in grammar!"
item))))
(let ((productions
@@ -467,9 +474,14 @@
(setq
parser-generator--table-translations
(make-hash-table :test 'equal))
+ (setq
+ parser-generator--table-productions-attributes
+ (make-hash-table :test 'equal))
(let ((production-index 0)
(new-productions))
+
+ ;; Iterate each production
(dolist (p productions)
(let ((lhs (car p))
(rhs (cdr p))
@@ -482,7 +494,10 @@
parser-generator--table-productions-rhs))
(rhs-element-index 0)
(rhs-length (length rhs))
- (rhs-element))
+ (rhs-element)
+ (production-attributes))
+
+ ;; Iterate each symbol in RHS
(while
(<
rhs-element-index
@@ -499,12 +514,17 @@
rhs-element
rhs
lhs))
+
+ ;; Potentially each symbol in RHS could be a separate RHS
(unless (listp rhs-element)
(setq rhs-element (list rhs-element)))
+
(let ((sub-rhs-element-index 0)
(sub-rhs-element-length (length rhs-element))
(sub-rhs-element)
(new-rhs))
+
+ ;; Iterate each symbol in SUB-RHS
(while
(<
sub-rhs-element-index
@@ -525,15 +545,21 @@
(parser-generator--valid-terminal-p sub-rhs-element)
(parser-generator--valid-non-terminal-p
sub-rhs-element)
(parser-generator--valid-e-p sub-rhs-element)
- (parser-generator--valid-eof-p sub-rhs-element))
+ (parser-generator--valid-eof-p sub-rhs-element)
+
(parser-generator--valid-context-sensitive-attribute-p sub-rhs-element))
(error
- "Element %s in RHS %s of production %s is not a valid
terminal, non-terminal, e-identifier or EOF-identifier!"
+ "Symbol %s in RHS %s of production %s is not a valid
terminal, non-terminal, context-sensitive attribute, e-identifier or
EOF-identifier!"
sub-rhs-element
rhs-element
lhs))
- (push
- sub-rhs-element
- new-rhs))
+ (if
(parser-generator--valid-context-sensitive-attribute-p
+ sub-rhs-element)
+ (push
+ sub-rhs-element
+ production-attributes)
+ (push
+ sub-rhs-element
+ new-rhs)))
(setq
sub-rhs-element-index
(1+ sub-rhs-element-index)))
@@ -564,6 +590,10 @@
production-index
production
parser-generator--table-productions-number-reverse)
+ (puthash
+ production-index
+ production-attributes
+ parser-generator--table-productions-attributes)
(push
production
new-productions)
@@ -837,26 +867,11 @@
(defun parser-generator--valid-non-terminal-p (symbol)
"Return whether SYMBOL is a non-terminal in grammar or not."
- (let ((valid-attribute t))
- (unless parser-generator--table-non-terminal-p
+ (unless parser-generator--table-non-terminal-p
(error "Table for non-terminals is undefined!"))
- (when (listp symbol)
- (unless
- (or
- (functionp symbol)
- (parser-generator--valid-context-sensitive-attribute-p
- (car (car (cdr symbol)))))
- (setq
- valid-attribute
- nil))
- (setq
- symbol
- (car symbol)))
- (and
- valid-attribute
- (gethash
- symbol
- parser-generator--table-non-terminal-p))))
+ (gethash
+ symbol
+ parser-generator--table-non-terminal-p))
(defun parser-generator--valid-production-p (production)
"Return whether PRODUCTION is valid or not."
@@ -1014,24 +1029,11 @@
(defun parser-generator--valid-terminal-p (symbol)
"Return whether SYMBOL is a terminal in grammar or not."
- (let ((valid-attribute t))
- (unless parser-generator--table-terminal-p
- (error "Table for terminals is undefined!"))
- (when (listp symbol)
- (unless
- (or
- (functionp symbol)
- (parser-generator--valid-context-sensitive-attribute-p
- (car (car (cdr symbol)))))
- (setq
- valid-attribute
- nil))
- (setq symbol (car symbol)))
- (and
- valid-attribute
- (gethash
- symbol
- parser-generator--table-terminal-p))))
+ (unless parser-generator--table-terminal-p
+ (error "Table for terminals is undefined!"))
+ (gethash
+ symbol
+ parser-generator--table-terminal-p))
;; Main Algorithms
- [elpa] externals/parser-generator ea02245 325/434: Improved debug output, (continued)
- [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, 2021/11/29
- [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 <=
- [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
- [elpa] externals/parser-generator 831a6e6 379/434: Made a commentary audit of parse according to GOTO and ACTION tables, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator bff0e63 380/434: Added TODO note, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 97b5e59 381/434: Comparing precedence of last symbol of production with look-ahead, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 5ff13d2 382/434: Improvements in test for precedence, ELPA Syncer, 2021/11/29
- [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