emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/parser-generator 71f03cc 171/434: Updated example


From: ELPA Syncer
Subject: [elpa] externals/parser-generator 71f03cc 171/434: Updated example
Date: Mon, 29 Nov 2021 15:59:34 -0500 (EST)

branch: externals/parser-generator
commit 71f03cc5a02ac9173bf176ec543abd92965a8cab
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>

    Updated example
---
 .../Deterministic-Right-Parser-for-LRk-Grammars.md | 54 +++++++++-------------
 1 file changed, 22 insertions(+), 32 deletions(-)

diff --git a/docs/Deterministic-Right-Parser-for-LRk-Grammars.md 
b/docs/Deterministic-Right-Parser-for-LRk-Grammars.md
index 4837347..65f7fb5 100644
--- a/docs/Deterministic-Right-Parser-for-LRk-Grammars.md
+++ b/docs/Deterministic-Right-Parser-for-LRk-Grammars.md
@@ -1,5 +1,9 @@
 # Deterministic Right Parser for LR(k) Grammars
 
+This library contains functions to parse and translate grammar as well as 
validate grammars.
+
+## LR Item
+
 A valid LR-item for a viable prefix has this structure:
 
 ``` emacs-lisp
@@ -57,46 +61,32 @@ Calculate the set of LR items valid for any viable prefix S.
 Perform a right-parse of input-stream.
 
 ```emacs-lisp
+(require 'parser-generator-lr)
 (require 'ert)
 
 (parser-generator-set-grammar '((Sp S) (a b) ((Sp S) (S (S a S b)) (S e)) Sp))
 (parser-generator-set-look-ahead-number 1)
 (parser-generator-process-grammar)
+(parser-generator-lr-generate-parser-tables)
 
 (setq
-   parser-generator-lex-analyzer--function
-   (lambda (index length)
-     (let* ((string '((a 1 . 2) (a 2 . 3) (b 3 . 4) (b 4 . 5) (b 5 . 6)))
-            (string-length (length string))
-            (max-index (+ index length))
-            (tokens))
-       (while (and
-               (< index string-length)
-               (< index max-index))
-         (push (nth index string) tokens)
-         (setq index (1+ index)))
-       (nreverse tokens))))
-(should
-   (equal
-    '(2 2 2 1 1)
-    (parser-generator-lr--parse)))
-    
+ parser-generator-lex-analyzer--function
+ (lambda (index)
+   (let* ((string '((a 1 . 2) (a 2 . 3) (b 3 . 4) (b 4 . 5)))
+          (string-length (length string))
+          (max-index index)
+          (tokens))
+     (while (and
+             (< (1- index) string-length)
+             (< (1- index) max-index))
+       (push (nth (1- index) string) tokens)
+       (setq index (1+ index)))
+     (nreverse tokens))))
 
-(setq
-   parser-generator-lex-analyzer--function
-   (lambda (index length)
-     (let* ((string '(a a b b b))
-            (string-length (length string))
-            (max-index (+ index length))
-            (tokens))
-       (while (and
-               (< index string-length)
-               (< index max-index))
-         (push (nth index string) tokens)
-         (setq index (1+ index)))
-       (nreverse tokens))))
-(should-error
-    (parser-generator-lr--parse))
+(should
+ (equal
+  '(2 2 2 1 1)
+  (parser-generator-lr-parse)))
 ```
 
 [Back to start](../../../)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]