Commit 32c427de2cee26531e1ad3f36f74bc17c7e9c348

Added base for grammar parser.
  
1(in-package :yacc-ebnf)
2
3(defun production-action (symbol derives)
4 (make-ebnf-production symbol derives))
5
6(defun make-grammar-grammar (&key name additional-terminals productions)
7 (make-ebnf-grammar
8 :name name
9 :start-symbol 'grammar
10 :terminals (cons 'id additional-terminals)
11 :precedence '()
12 :productions (append
13 (make-ebnf-production 'literal '(id) :action #'identity)
14 (make-ebnf-production 'rule-name '(id) :action #'identity)
15 productions)))
16
17(defun make-grammar-maker (grammar-grammar)
18 (lambda (lexer &key name (start-symbol (required-argument)) terminals precedence)
19 (make-ebnf-grammar
20 :name name
21 :start-symbol start-symbol
22 :terminals terminals
23 :precedence precedence
24 :productions (parse-with-lexer lexer (make-ebnf-parser grammar-grammar)))))
  
2525(asdf:defsystem #:yacc-ebnf
2626 :depends-on (#:yacc #:alexandria)
2727 :components ((:file "package")
28 (:file "yacc-ebnf" :depends-on ("package"))))
28 (:file "yacc-ebnf" :depends-on ("package"))
29 (:file "grammar-parser" :depends-on ("yacc-ebnf"))))
  
4343
4444(defun expand-ebnf (symbol derives &key (operation '()))
4545 (let ((add-prods '()))
46 (append
47 (case operation
48 (:repeat
49 (make-repeat symbol derives))
50 (:option
51 (make-option symbol derives))
52 (:or
53 (make-or symbol derives))
54 (:plus
55 (make-plus symbol derives))
56 (otherwise
57 (list
58 (make-ebnf-prod
59 :symbol symbol
60 :derives
61 (mapcar #'(lambda (el)
62 (if (consp el)
63 (let ((gensym (make-gensym "production")))
64 (appendf add-prods (expand-ebnf gensym (cdr el) :operation (car el)))
65 gensym)
66 el))
67 derives)))))
68 add-prods)))
46 (if (and (consp derives) (member (car derives) '(:repeat :option :or :plus)))
47 (expand-ebnf symbol (cdr derives) :operation (car derives))
48 (progn
49 (append
50 (case operation
51 (:repeat
52 (make-repeat symbol derives))
53 (:option
54 (make-option symbol derives))
55 (:or
56 (make-or symbol derives))
57 (:plus
58 (make-plus symbol derives))
59 (otherwise
60 (list
61 (make-ebnf-prod
62 :symbol symbol
63 :derives
64 (mapcar #'(lambda (el)
65 (if (consp el)
66 (let ((gensym (make-gensym "production")))
67 (appendf add-prods (expand-ebnf gensym (cdr el) :operation (car el)))
68 gensym)
69 el))
70 derives)))))
71 add-prods)))))
6972
7073(defun make-ebnf-production (symbol derives &key (action #'list) (action-form '()))
7174 "Creates a list of cl-yacc bnf productions from lispy ebnf notation"