[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/parser-generator 7ee5504003 45/82: More work on LLk par
From: |
Christian Johansson |
Subject: |
[elpa] externals/parser-generator 7ee5504003 45/82: More work on LLk parser |
Date: |
Thu, 12 May 2022 13:28:16 -0400 (EDT) |
branch: externals/parser-generator
commit 7ee5504003bcc1c0a7fbc9e090ba65812d608307
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
More work on LLk parser
---
parser-generator-ll.el | 48 ++++++++++++++++++++++-------------
test/parser-generator-ll-test.el | 55 ++++++++++++++++++++++++++++++++++------
2 files changed, 78 insertions(+), 25 deletions(-)
diff --git a/parser-generator-ll.el b/parser-generator-ll.el
index 649ebd26a4..19ff1790fd 100644
--- a/parser-generator-ll.el
+++ b/parser-generator-ll.el
@@ -47,18 +47,18 @@
(state-look-ahead-production-number
(nth 3 state-look-ahead-list)))
(puthash
- state-look-ahead-string
+ (format "%S" state-look-ahead-string)
(list
state-look-ahead-action
state-look-ahead-reduction
state-look-ahead-production-number)
state-hash-table))
(puthash
- state-look-ahead-string
+ (format "%S" state-look-ahead-string)
state-look-ahead-action
state-hash-table))))
(puthash
- state-key
+ (format "%S" state-key)
state-hash-table
hash-parsing-table)))
(setq
@@ -84,30 +84,37 @@
(let* ((state (car stack))
(state-action-table
(gethash
- state
+ (format "%S" state)
parser-generator-ll--parsing-table))
(look-ahead-list
(parser-generator-lex-analyzer--peek-next-look-ahead))
(look-ahead))
+ (message "\nstate: %S" state)
+ (message "\nstate-action-table: %S" state-action-table)
(unless state-action-table
(signal
'error
- (format
- "State action table lacks actions for state: '%S'!"
- state)))
+ (list
+ (format
+ "State action table lacks actions for state: '%S'!"
+ state))))
- (unless look-ahead
- (signal
- 'error
- (format
- "Reached end of input without accepting!")))
+ (if look-ahead-list
+ (progn
+ (message "look-ahead-list: %S" look-ahead-list)
+ (setq
+ look-ahead
+ (list (car (car look-ahead-list)))))
+ (setq
+ look-ahead
+ (list parser-generator--eof-identifier)))
- (setq
- look-ahead
- (car (car look-ahead-list)))
+ (message "look-ahead: %S" look-ahead)
- (unless (gethash look-ahead state-action-table)
+ (unless (gethash
+ (format "%S" look-ahead)
+ state-action-table)
(let ((possible-look-aheads))
(maphash
(lambda (k _v) (push k possible-look-aheads))
@@ -120,17 +127,24 @@
state
possible-look-aheads))))
- (let* ((action (gethash look-ahead state-action-table))
+ (let* ((action
+ (gethash
+ (format "%S" look-ahead)
+ state-action-table))
(action-type action))
+ (message "action: %S" action)
(when (listp action)
(setq action-type (car action)))
+ (message "action-type: %S" action-type)
(cond
((equal action-type 'pop)
+ (message "pushed: %S" look-ahead-list)
(push
(car (parser-generator-lex-analyzer--pop-token))
stack))
((equal action-type 'reduce)
+ (message "reduced: %S" (nth 1 action))
(push
(nth 1 action)
stack)
diff --git a/test/parser-generator-ll-test.el b/test/parser-generator-ll-test.el
index 2f260c10d6..03d012f2e0 100644
--- a/test/parser-generator-ll-test.el
+++ b/test/parser-generator-ll-test.el
@@ -293,7 +293,7 @@
)
(parser-generator-process-grammar)
(parser-generator-ll-generate-parser-tables)
- (message "parser-generator-ll--parsing-table: %S"
parser-generator-ll--parsing-table)
+ ;; (message "parser-generator-ll--parsing-table: %S"
parser-generator-ll--parsing-table)
(setq
parser-generator-lex-analyzer--function
(lambda (index)
@@ -348,13 +348,52 @@
(should
(equal
'(
- (((S) ($)) (((a b) (reduce (a b ((A) ($))) 1)) (($ $) (reduce (e) 0))))
- (((A) ($)) (((b $) (reduce (b) 3)) ((a a) (reduce (((S) (a a)) a a) 2))
((a b) (reduce (((S) (a a)) a a) 2))))
- (((S) (a a)) (((a a) (reduce (e) 0)) ((a b) (reduce (a b ((A) (a a)))
1))))
- (((A) (a a)) (((b a) (reduce (b) 3)) ((a a) (reduce (((S) (a a)) a a)
2)) ((a b) (reduce (((S) (a a)) a a) 2))))
- (b (((b b) pop) ((b a) pop) ((b $) pop)))
- (a (((a b) pop) ((a a) pop) ((a $) pop)))
- ($ ((($ $) accept))))
+ ("((S) ($))"
+ (
+ ("(a b)" (reduce (a b ((A) ($))) 1))
+ ("($ $)" (reduce (e) 0))
+ )
+ )
+ ("((A) ($))"
+ (
+ ("(b $)" (reduce (b) 3))
+ ("(a a)" (reduce (((S) (a a)) a a) 2))
+ ("(a b)" (reduce (((S) (a a)) a a) 2))
+ )
+ )
+ ("((S) (a a))"
+ (
+ ("(a a)" (reduce (e) 0))
+ ("(a b)" (reduce (a b ((A) (a a))) 1))
+ )
+ )
+ ("((A) (a a))"
+ (
+ ("(b a)" (reduce (b) 3))
+ ("(a a)" (reduce (((S) (a a)) a a) 2))
+ ("(a b)" (reduce (((S) (a a)) a a) 2))
+ )
+ )
+ ("b"
+ (
+ ("(b b)" pop)
+ ("(b a)" pop)
+ ("(b $)" pop)
+ )
+ )
+ ("a"
+ (
+ ("(a b)" pop)
+ ("(a a)" pop)
+ ("(a $)" pop)
+ )
+ )
+ ("$"
+ (
+ ("($ $)" accept)
+ )
+ )
+ )
(parser-generator--hash-to-list
parser-generator-ll--parsing-table
t)))
- [elpa] externals/parser-generator 08af836006 69/82: More work on SDT for LL grammar, (continued)
- [elpa] externals/parser-generator 08af836006 69/82: More work on SDT for LL grammar, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 7d87a2d154 79/82: Implemented exported LL(k) and LL(1) parser, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 75323b10e5 81/82: Merge branch 'feature/llk-parser', Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator db91a5f203 82/82: Removed unused function, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 315e40eff8 10/82: More work on LL table generation, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 34ab0f1718 21/82: More various tweaks, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 064bd259ff 26/82: Passing LLk validation tests, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator f0de6698b9 29/82: Added todo item, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 97919972a7 35/82: Improved debug message, added TODO item, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator e55a3f8a37 38/82: Updated TODO items, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 7ee5504003 45/82: More work on LLk parser,
Christian Johansson <=
- [elpa] externals/parser-generator fd2f90dd81 47/82: Added TODO-item, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator b41b2dbffe 68/82: Removed debug output, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 566228f16c 71/82: More work on LLk translation, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 234a6ca2db 70/82: More work on LLk SDT, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator ff261d9a4e 75/82: Using stack for symbols value in SDT, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator de7c45c511 78/82: Started with LL-export functions, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 5be162966b 80/82: Fixed byte-compilation issue in exported LL parser, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 2869417d78 31/82: Made new helper functions to make LL-parsing easier, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 23805731c1 34/82: More work on LL-parser, Christian Johansson, 2022/05/12
- [elpa] externals/parser-generator 8cc2a5b315 44/82: More work on LLk parsing, Christian Johansson, 2022/05/12