Commit f05f97c5f1cac0de6b05e9a474ff5a713eda58e0
- Diff rendering mode:
- inline
- side by side
src/yacc-ebnf.lisp
(26 / 6)
|   | |||
| 26 | 26 | ||
| 27 | 27 | (defstruct ebnf-prod symbol derives) | |
| 28 | 28 | ||
| 29 | (defun make-or (symbol derives) | ||
| 30 | (mapcan | ||
| 31 | #'(lambda (derive) | ||
| 32 | (expand-ebnf symbol (if (listp derive) derive (list derive)))) | ||
| 33 | derives)) | ||
| 34 | |||
| 29 | 35 | (defun make-repeat (symbol derives) | |
| 30 | (append | ||
| 31 | (expand-ebnf symbol derives :operation :option) | ||
| 32 | (list (make-ebnf-prod :symbol symbol :derives (list symbol))))) | ||
| 36 | (expand-ebnf symbol (list derives symbol '()) :operation :or)) | ||
| 33 | 37 | ||
| 34 | 38 | (defun make-option (symbol derives) | |
| 35 | (append | ||
| 36 | (expand-ebnf symbol derives) | ||
| 37 | (list (make-ebnf-prod :symbol symbol :derives '())))) | ||
| 39 | (expand-ebnf symbol (list derives '()) :operation :or)) | ||
| 38 | 40 | ||
| 39 | 41 | (defun expand-ebnf (symbol derives &key (operation '())) | |
| 40 | 42 | (let ((add-prods '())) | |
| … | … | ||
| 46 | 46 | (make-repeat symbol derives)) | |
| 47 | 47 | (:option | |
| 48 | 48 | (make-option symbol derives)) | |
| 49 | (:or | ||
| 50 | (make-or symbol derives)) | ||
| 49 | 51 | (otherwise | |
| 50 | 52 | (list | |
| 51 | 53 | (make-ebnf-prod | |
| … | … | ||
| 71 | 71 | :action action | |
| 72 | 72 | :action-form action-form)) | |
| 73 | 73 | (expand-ebnf symbol derives))) | |
| 74 | |||
| 75 | (defun make-ebnf-grammar (&key name (start-symbol (required-argument)) terminals precedence productions) | ||
| 76 | (make-grammar :name name :start-symbol start-symbol :terminals terminals :precedence precedence :productions productions)) | ||
| 77 | |||
| 78 | (defun make-ebnf-parser (grammar | ||
| 79 | &key (discard-memos t) (muffle-conflicts nil) | ||
| 80 | (print-derives-epsilon nil) (print-first-terminals nil) | ||
| 81 | (print-states nil) | ||
| 82 | (print-goto-graph nil) (print-lookaheads nil)) | ||
| 83 | (make-parser grammar | ||
| 84 | :discard-memos discard-memos :muffle-conflicts muffle-conflicts | ||
| 85 | :print-derives-epsilon print-derives-epsilon | ||
| 86 | :print-first-terminals print-first-terminals | ||
| 87 | :print-states print-states | ||
| 88 | :print-goto-graph print-goto-graph | ||
| 89 | :print-lookaheads print-lookaheads)) |

