[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/parser-generator 03ca2e9 247/434: Look-ahead generation
From: |
ELPA Syncer |
Subject: |
[elpa] externals/parser-generator 03ca2e9 247/434: Look-ahead generation now supports EOF symbol |
Date: |
Mon, 29 Nov 2021 15:59:50 -0500 (EST) |
branch: externals/parser-generator
commit 03ca2e98ee2b6b3d35a3ef15a893d090bf3bcb32
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Look-ahead generation now supports EOF symbol
---
parser-generator-lr.el | 11 ++++++++
parser-generator.el | 72 ++++++++++++++++++++++++++++++++------------------
2 files changed, 58 insertions(+), 25 deletions(-)
diff --git a/parser-generator-lr.el b/parser-generator-lr.el
index e2fffd3..1def311 100644
--- a/parser-generator-lr.el
+++ b/parser-generator-lr.el
@@ -70,10 +70,21 @@
(let ((C (nth 2 lr-item))
(v (nth 3 lr-item)))
(let ((Cv (append C v)))
+ (parser-generator--debug
+ (message
+ "Cv: %s from %s + %s"
+ Cv
+ C
+ v))
(when Cv
(let
((eff
(parser-generator--e-free-first Cv)))
+ (parser-generator--debug
+ (message
+ "E-FREE-FIRST %s = %s"
+ Cv
+ eff))
(if eff
;; Go through eff-items and see if any item
is a valid look-ahead of grammar
;; in that case save in action table a shift
action here
diff --git a/parser-generator.el b/parser-generator.el
index 1babaad..296cc0a 100644
--- a/parser-generator.el
+++ b/parser-generator.el
@@ -107,27 +107,22 @@
"Return all possible look-ahead set."
(unless parser-generator--look-ahead-number
(error "No look-ahead number defined!"))
- (let ((terminals (parser-generator--get-grammar-terminals))
+ (let ((terminals
+ (parser-generator--get-grammar-terminals))
(look-aheads)
(k parser-generator--look-ahead-number)
(stack '((0 0 nil)))
(marked-paths (make-hash-table :test 'equal))
(added-look-aheads (make-hash-table :test 'equal)))
- (let ((terminals-max-index (1- (length terminals)))
+ (let ((terminals-max-index
+ (1- (length terminals)))
(terminal-index)
(look-ahead-length)
(look-ahead)
- (eof-list))
-
- (let ((eof-list-index 0)
- (eof-list-length parser-generator--look-ahead-number))
- (while (< eof-list-index eof-list-length)
- (push
- parser-generator--eof-identifier
- eof-list)
- (setq
- eof-list-index
- (1+ eof-list-index))))
+ (eof-list
+ (parser-generator--generate-list-of-symbol
+ k
+ parser-generator--eof-identifier)))
(while stack
(let ((item (pop stack)))
@@ -143,9 +138,14 @@
(push next-terminal potential-look-ahead)
(if (gethash potential-look-ahead marked-paths)
(setq terminal-index (1+ terminal-index))
- (puthash potential-look-ahead t marked-paths)
+ (puthash
+ potential-look-ahead
+ t
+ marked-paths)
- (push `(,terminal-index ,look-ahead-length,look-ahead) stack)
+ (push
+ `(,terminal-index ,look-ahead-length,look-ahead)
+ stack)
(setq look-ahead-length (1+ look-ahead-length))
(setq look-ahead potential-look-ahead)
@@ -163,16 +163,31 @@
(setq
look-ahead-length
(1+ look-ahead-length)))
- (setq look-ahead-to-add (reverse look-ahead)))
-
- (setq look-ahead-to-add eof-list))
-
- (when (and look-ahead-to-add
- (not (gethash look-ahead-to-add added-look-aheads)))
- (puthash look-ahead-to-add t added-look-aheads)
- (push look-ahead-to-add look-aheads))))))
+ (setq
+ look-ahead-to-add
+ (reverse look-ahead)))
+
+ (setq
+ look-ahead-to-add
+ eof-list))
+
+ (when
+ (and look-ahead-to-add
+ (not
+ (gethash
+ look-ahead-to-add
+ added-look-aheads)))
+ (puthash
+ look-ahead-to-add
+ t
+ added-look-aheads)
+ (push
+ look-ahead-to-add
+ look-aheads))))))
- (sort look-aheads 'parser-generator--sort-list)))
+ (sort
+ look-aheads
+ 'parser-generator--sort-list)))
(defun parser-generator--get-grammar-non-terminals (&optional G)
"Return non-terminals of grammar G."
@@ -540,7 +555,9 @@
(error "Table for look-aheads is undefined!"))
(unless (listp symbol)
(setq symbol (list symbol)))
- (gethash symbol parser-generator--table-look-aheads-p))
+ (gethash
+ symbol
+ parser-generator--table-look-aheads-p))
(defun parser-generator--valid-look-ahead-number-p (k)
"Return if look-ahead number K is valid or not."
@@ -1185,6 +1202,7 @@
(parser-generator--debug
(message "symbol index: %s from %s is: %s" input-tape-index
input-tape symbol))
(cond
+
((parser-generator--valid-e-p symbol)
(if disallow-e-first
(when (> first-length 0)
@@ -1194,6 +1212,10 @@
(setq first-length (1+ first-length)))
(setq keep-looking nil))
+ ((parser-generator--valid-eof-p symbol)
+ (setq first (append first (list symbol)))
+ (setq first-length (1+ first-length)))
+
((parser-generator--valid-terminal-p symbol)
(setq first (append first (list symbol)))
(setq first-length (1+ first-length)))
- [elpa] externals/parser-generator 069bf34 209/434: Added test for new helper function list of symbol, (continued)
- [elpa] externals/parser-generator 069bf34 209/434: Added test for new helper function list of symbol, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator c8c130e 226/434: Improved error messages, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 80f99cf 241/434: Added failing unit test for lr-items set k=2, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 5032a77 233/434: Fixed typo in Lex Analyzer error, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 07320b9 249/434: Updated test-case k=2, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator d49f74f 244/434: Added failing test for action-tables LRk parser k=2, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator fe05328 250/434: Passed unit tests for LRk parser k=2, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator d1f4682 248/434: Added a function that converts a FIRST-item to a look-ahead item, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 6845262 243/434: Passed GOTO-tables k=2, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 3a0d4cd 255/434: Added translation test for LRk=2, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 03ca2e9 247/434: Look-ahead generation now supports EOF symbol,
ELPA Syncer <=
- [elpa] externals/parser-generator 3563720 266/434: Updated docs about lexical analysis, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 412fd2a 273/434: Passing generation of GOTO-table for LR(0) grammar, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator bc23604 274/434: Fixed look-ahead, first and e-free-first with k = 0, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 1879cb0 271/434: Merge branch 'master' of git.cvj.se:/home/git/emacs-parser-generator, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 16bb2d8 262/434: Added translation example LRk parser, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator d173c1e 281/434: More work on exporting parser as code function, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator bd887ff 277/434: LR(0) Parser passing translation test, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 852f969 283/434: Merge branch 'master' of git.cvj.se:/home/git/emacs-parser-generator, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 0d6d46d 294/434: Debugging incremental issue with exported translator, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator c4c68b2 302/434: Added progress-indicator to goto-table generation, ELPA Syncer, 2021/11/29