branch: externals/parser-generator commit 58798c811883aad7304fd528d2513a9b0ed6ca5a Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Starting on calculation of valid LK-sets for a valid grammar prefix --- parser.el | 11 +++++++++-- test/parser-test.el | 46 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/parser.el b/parser.el index a6af40c..1a6fb09 100644 --- a/parser.el +++ b/parser.el @@ -9,8 +9,6 @@ (defvar parser--debug nil) -;; page 402 - (defmacro parser--debug (&rest message) "Output MESSAGE but only if debug is enabled." `(when parser--debug @@ -198,10 +196,19 @@ (push leading-terminals f-set)))))) f-set)) +;; page 402 (defun parser--empty-free-first (k production productions) "Calculate empty-free-first K tokens of PRODUCTION in PRODUCTIONS." (parser--first k production productions t)) +(defun parser--v-set (viable-prefix productions start) + "Calculate valid LR-sets for each VIABLE-PREFIX of PRODUCTIONS from START." + (let ((v-set)) + (dolist (production productions) + ) + v-set)) + + (provide 'parser) ;;; parser.el ends here diff --git a/test/parser-test.el b/test/parser-test.el index b96a219..6ded36e 100644 --- a/test/parser-test.el +++ b/test/parser-test.el @@ -9,8 +9,24 @@ (require 'parser) (require 'ert) +(defun parser-test--distinct () + "Test `parser--distinct'." + (message "Starting tests for (parser--distinct)") + + (should + (equal + '(a b c) + (parser--distinct '(a a b c)))) + + (should + (equal + '("aa" "b" "cc" "c" "a") + (parser--distinct '("aa" "b" "cc" "c" "b" "a" "aa")))) + (message "Passed tests for (parser--distinct)")) + (defun parser-test--first () "Test `parser--first'." + (message "Starting tests for (parser--first)") (should (equal @@ -156,8 +172,9 @@ ;; Example 5.28 page 402 (defun parser-test--empty-free-first () "Test `parser--empty-free-first'." + (message "Starting tests for (parser-test--empty-free-first)") - ;; Example 5.28 p 402 + ;; Example 5.28 p 402 (should (equal '("ca" "cb") @@ -173,24 +190,31 @@ (message "Passed tests for (parser-test--empty-free-first)")) -(defun parser-test--distinct () - "Test `parser--distinct'." - (should - (equal - '(a b c) - (parser--distinct '(a a b c)))) +(defun parser-test--v-set () + "Test `parser--v-set'." + (message "Starting tests for (parser-test--v-set)") + ;; Example 5.29 p 407 (should (equal - '("aa" "b" "cc" "c" "a") - (parser--distinct '("aa" "b" "cc" "c" "b" "a" "aa")))) - (message "Passed tests for (parser--distinct)")) + '("ca" "cb") + (parser--v-set + 'e + '((S' S) + (S SaSb) + (S e)) + 'S'))) + (message "Passed empty-free-first 2 with complex grammar") + + (message "Passed tests for (parser-test--v-set)")) + (defun parser-test () "Run test." (parser-test--distinct) (parser-test--first) - (parser-test--empty-free-first)) + (parser-test--empty-free-first) + (parser-test--v-set)) (provide 'parser-test)