[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/parser-generator 928b31d 343/434: More work on infix ca
From: |
ELPA Syncer |
Subject: |
[elpa] externals/parser-generator 928b31d 343/434: More work on infix calculator |
Date: |
Mon, 29 Nov 2021 16:00:12 -0500 (EST) |
branch: externals/parser-generator
commit 928b31de59e3ead86ac6d4faf9f0a05e857b020f
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
More work on infix calculator
---
test/parser-generator-lr-test.el | 79 ++++++++++++++++++++++++++--------------
1 file changed, 52 insertions(+), 27 deletions(-)
diff --git a/test/parser-generator-lr-test.el b/test/parser-generator-lr-test.el
index 4b4b9ce..b99a894 100644
--- a/test/parser-generator-lr-test.el
+++ b/test/parser-generator-lr-test.el
@@ -518,7 +518,7 @@
(input line))
(line
"\n"
- (exp "+" (lambda(args) (message "%s" args))))
+ (exp "\n"))
(exp
NUM
(exp "+" exp (lambda(args) (+ (nth 0 args) (nth 2 args))))
@@ -534,29 +534,46 @@
(lambda (index)
(with-current-buffer "*buffer*"
(let ((token))
- (goto-char index)
- (cond
- ((looking-at "[0-9]+")
- (setq
- token
- `(NUM ,(match-beginning 0) ,(match-end 0))))
- ((looking-at "\\(\\+\\|\-\\|\*\\|\/\\|\\^\\|)\\|(\\|\n\\)")
- (let ((symbol
- (buffer-substring-no-properties
- (match-beginning 0)
- (match-end 0))))
+ (when
+ (<
+ index
+ (point-max))
+ (goto-char
+ index)
+ (cond
+ ((looking-at "[0-9]+")
(setq
token
- `(,symbol ,(match-beginning 0) . ,(match-end 0)))))
- (t (error "Unexpected input at %d!" index)))
+ `(NUM ,(match-beginning 0) . ,(match-end 0))))
+ ((looking-at "\\(\\+\\|\-\\|\*\\|\/\\|\\^\\|)\\|(\\|\n\\)")
+ (let ((symbol
+ (buffer-substring-no-properties
+ (match-beginning 0)
+ (match-end 0))))
+ (setq
+ token
+ `(,symbol ,(match-beginning 0) . ,(match-end 0)))))
+ (t (error "Unexpected input at %d!" index))))
token))))
(setq
parser-generator-lex-analyzer--get-function
- (lambda (token) (car token)))
+ (lambda (token)
+ (with-current-buffer "*buffer*"
+ (let ((start (car (cdr token)))
+ (end (cdr (cdr token))))
+ (when (<= end (point-max))
+ (let ((symbol
+ (buffer-substring-no-properties start end)))
+ (when
+ (string-match-p "^[0-9]+$" symbol)
+ (setq
+ symbol
+ (string-to-number symbol)))
+ symbol))))))
(parser-generator-process-grammar)
- (should-error
- (parser-generator-lr-generate-parser-tables))
+ ;; (should-error
+ ;; (parser-generator-lr-generate-parser-tables))
(message "Infix calculator grammar caused expected error")
;; Add precedence to resolve conflicts
@@ -627,16 +644,16 @@
(input line))
(line
"\n"
- (exp "+" (lambda(args) (message "%s" args))))
+ (exp "\n"))
(exp
NUM
- (exp "+" exp (lambda(args) (+ (nth 0 args) (nth 2 args))))
- (exp "-" exp (lambda(args) (- (nth 0 args) (nth 2 args))))
- (exp "*" exp (lambda(args) (* (nth 0 args) (nth 2 args))))
- (exp "/" exp (lambda(args) (/ (nth 0 args) (nth 2 args))))
- ("-" (exp (%prec NEG)) (lambda(args) (- (nth 1 args))))
- (exp "^" exp (lambda(args) (expt (nth 0 args) (nth 2 args))))
- ("(" exp ")" (lambda(args) (nth 1)))))
+ (exp "+" exp (lambda(args) (+ (car (nth 0 args)) (car (nth 2 args)))))
+ (exp "-" exp (lambda(args) (- (car (nth 0 args)) (car (nth 2 args)))))
+ (exp "*" exp (lambda(args) (* (car (nth 0 args)) (car (nth 2 args)))))
+ (exp "/" exp (lambda(args) (/ (car (nth 0 args)) (car (nth 2 args)))))
+ ("-" (exp (%prec NEG)) (lambda(args) (- (car (nth 1 args)))))
+ (exp "^" exp (lambda(args) (expt (car (nth 0 args)) (car (nth 2
args)))))
+ ("(" exp ")" (lambda(args) (car (nth 1 args))))))
start))
(parser-generator-process-grammar)
@@ -648,11 +665,19 @@
(switch-to-buffer buffer)
(kill-region (point-min) (point-max))
(insert "5+5\n")
- (parser-generator-lr-translate)
(should
(equal
10
- (parser-generator-lr-translate))))
+ (car (parser-generator-lr-translate))))
+
+ (switch-to-buffer buffer)
+ (kill-region (point-min) (point-max))
+ (insert "7-3\n")
+ (should
+ (equal
+ 4
+ (parser-generator-lr-translate)))
+ (kill-buffer))
(message "Passed tests for (parser-generator-lr--parse)"))
- [elpa] externals/parser-generator bd887ff 277/434: LR(0) Parser passing translation test, (continued)
- [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
- [elpa] externals/parser-generator 586789d 308/434: Added cache to first calculation, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 236a124 322/434: More work on resolving conflicts, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 04c360b 318/434: LR-items set validation now supports symbols with attributes, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator ea02245 325/434: Improved debug output, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator e56bcff 324/434: Improved output of productions and action-tables, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator fb29641 337/434: Passing old context-sensitive precedence example with new structure, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 928b31d 343/434: More work on infix calculator,
ELPA Syncer <=
- [elpa] externals/parser-generator 6a4b353 344/434: More work on translations, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 85d1b49 345/434: Infix calculator translation passing some tests, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 08e9876 347/434: Fixed bug with associating a translation to multiple productions, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator c6d3ad2 352/434: Infix calculator working as expected without precedence rules, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 21948c8 358/434: Fixed lex-analyzer to infix calculator test to support white-space and floats, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 14711d4 363/434: Added more debug stuff, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator f0f2daa 364/434: Started refactor of context-sensitive attributes, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 7e1d2fb 368/434: Added TODO notes, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 5a1f09a 369/434: More work on adding support for production number related precedence, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator e4658d9 372/434: LR action-table generation is now using context-sensitive precedence resolution for reduce/reduce conflicts, ELPA Syncer, 2021/11/29