branch: externals/parser-generator
commit 34ab0f171829eb984597852c08b895259ef66ac2
Author: Christian Johansson <[email protected]>
Commit: Christian Johansson <[email protected]>
More various tweaks
---
parser-generator-ll.el | 27 +++++++++++++++++++++------
test/parser-generator-ll-test.el | 40 +++++++++++++++++++++++++++++++---------
2 files changed, 52 insertions(+), 15 deletions(-)
diff --git a/parser-generator-ll.el b/parser-generator-ll.el
index 4356d5f906..5ec448db43 100644
--- a/parser-generator-ll.el
+++ b/parser-generator-ll.el
@@ -232,13 +232,28 @@
(dolist (table tables)
(let* ((key (nth 0 table))
(value (nth 1 table))
- (stack-symbol (car (nth 0 key)))
- (local-follow-set (nth 1 key)))
+ (key-stack-symbol (car (nth 0 key)))
+ (key-parent-follow-set (nth 1 key))
+ (parse-table))
(dolist (look-ahead-row value)
- (let ((look-ahead (nth 0 look-ahead-row))
- (right-hand-side (nth 1 look-ahead-row)))
- (dolist (right-hand-symbol right-hand-side))
- ))))
+ (let* ((look-ahead (nth 0 look-ahead-row))
+ (right-hand-side (nth 1 look-ahead-row))
+ (local-follow-sets (nth 2 look-ahead-row))
+ (non-terminal-index 0)
+ (sub-symbol-index 0)
+ (sub-symbol-length (length right-hand-side)))
+ (while (< sub-symbol-index sub-symbol-length)
+ (let ((sub-symbol (nth sub-symbol-index right-hand-side)))
+ (when (parser-generator--valid-non-terminal-p
+ sub-symbol)
+ (let ((local-follow (nth non-terminal-index
local-follow-sets)))
+ )
+ (setq
+ non-terminal-index
+ (1+ non-terminal-index))))
+ (setq
+ sub-symbol-index
+ (1+ sub-symbol-index)))))))
;;
;; (2) M(a, av) = pop for all v in E where |E| = k-1 -> move to parser
logic
diff --git a/test/parser-generator-ll-test.el b/test/parser-generator-ll-test.el
index 6585373579..7a5f86dbe2 100644
--- a/test/parser-generator-ll-test.el
+++ b/test/parser-generator-ll-test.el
@@ -74,9 +74,31 @@
(parser-generator-set-e-identifier 'e)
(parser-generator-set-look-ahead-number 2)
(let* ((tables
- '((((A) (b a)) (((b b) (b) nil) ((b a) (e) nil)))
- (((A) (a a)) (((a a) (e) nil) ((b a) (b) nil)))
- (((S) nil) (((a b) (a A a a) ((a a))) ((a a) (a A a a) ((a a)))
((b b) (b A b a) ((b a)))))))
+ '(
+ (
+ ((A) (b a))
+ (
+ ((b b) (b) nil)
+ ((b a) (e) nil)
+ )
+ )
+ (
+ ((A) (a a))
+ (
+ ((a a) (e) nil)
+ ((b a) (b) nil)
+ )
+ )
+ (
+ ((S) nil)
+ (
+ ((a b) (a A a a) ((a a)))
+ ((a a) (a A a a) ((a a)))
+ ((b b) (b A b a) ((b a)))
+ )
+ )
+ )
+ )
(parser-tables
(parser-generator-ll--generate-parsing-table
tables)))
@@ -87,22 +109,22 @@
(equal
'(
(
- ((S) nil)
+ ((S) nil) ;; T0
(
- ((a a) reduce (a T1 a a) 1)
- ((a b) reduce (a T1 a a) 1)
- ((b b) reduce (b T2 b a) 2)
+ ((a a) reduce (a ((A) (a a)) a a) 1)
+ ((a b) reduce (a ((A) (a a)) a a) 1)
+ ((b b) reduce (b ((A) (b a)) b a) 2)
)
)
(
- ((A) (a a))
+ ((A) (a a)) ;; T1
(
((a a) reduce (e) 4)
((b a) reduce (b) 3)
)
)
(
- ((A) (a b))
+ ((A) (a b)) ;; T2
(
((b a) reduce (e) 4)
((b b) reduce (b) 3)