Parse a sequence of natural numbers as an ABNF grammar.
This is a declaratively defined, non-executable parser for the ABNF language itself (parse-grammar is a verified executable parser). It turns text (represented as a sequence of natural numbers) with ABNF grammar rules (defining the concrete syntax of some language) into parse trees; the parse trees can be abstracted to lists of rules in the ABNF abstract syntax.
This function may return more than one parse tree,
because the
This ambiguity only concerns blank space and comments, so it does not affect the abstract syntax and the semantics.
It remains to be proved that this function
always returns a finite set of trees, never
Function:
(defun parse-grammar* (nats) (declare (xargs :guard (nat-listp nats))) (parse nats *rulelist* *grammar*))
Theorem:
(defthm return-type-of-parse-grammar* (b* ((result (parse-grammar* nats))) (or (tree-setp result) (equal result :infinite))) :rule-classes :rewrite)
Theorem:
(defthm rulelist-ambiguous-example (b* ((string (list *rulename* *defined-as* *alternation* *c-nl* *wsp* *c-nl*)) (tree-rulename (tree-leafrule *rulename*)) (tree-defined-as (tree-leafrule *defined-as*)) (tree-alternation (tree-leafrule *alternation*)) (tree-c-nl (tree-leafrule *c-nl*)) (tree-wsp (tree-leafrule *wsp*)) (tree-c-nl-wsp (tree-nonleaf nil (list (list tree-c-nl) (list tree-wsp)))) (tree-c-wsp-1 (tree-nonleaf *c-wsp* (list (list tree-c-nl-wsp)))) (tree-c-wsp-2 (tree-nonleaf *c-wsp* (list (list tree-wsp)))) (tree-elements-1 (tree-nonleaf *elements* (list (list tree-alternation) (list tree-c-wsp-1)))) (tree-elements-2 (tree-nonleaf *elements* (list (list tree-alternation) nil))) (tree-rule-1 (tree-nonleaf *rule* (list (list tree-rulename) (list tree-defined-as) (list tree-elements-1) (list tree-c-nl)))) (tree-rule-/-*cwsp-cnl-1 (tree-nonleaf nil (list (list tree-rule-1)))) (tree-rulelist-1 (tree-nonleaf *rulelist* (list (list tree-rule-/-*cwsp-cnl-1)))) (tree-rule-2 (tree-nonleaf *rule* (list (list tree-rulename) (list tree-defined-as) (list tree-elements-2) (list tree-c-nl)))) (tree-rule-/-*cwsp-cnl-2 (tree-nonleaf nil (list (list tree-rule-2)))) (tree-*cwsp-cnl (tree-nonleaf nil (list (list tree-c-wsp-2) (list tree-c-nl)))) (tree-rule-/-*cwsp-cnl-3 (tree-nonleaf nil (list (list tree-*cwsp-cnl)))) (tree-rulelist-2 (tree-nonleaf *rulelist* (list (list tree-rule-/-*cwsp-cnl-2 tree-rule-/-*cwsp-cnl-3))))) (and (stringp string) (treep tree-rulelist-1) (treep tree-rulelist-2) (tree-match-element-p tree-rulelist-1 (element-rulename *rulelist*) *grammar*) (tree-match-element-p tree-rulelist-2 (element-rulename *rulelist*) *grammar*) (not (equal tree-rulelist-1 tree-rulelist-2)) (equal (tree->string tree-rulelist-1) string) (equal (tree->string tree-rulelist-2) string))))