Parse EBNF: Difference between revisions

Content added Content deleted
m (→‎{{header|PicoLisp}}: Flag problem)
(Parse EBNF from string format)
Line 12: Line 12:


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(de EBNF
{{improve|PicoLisp|The input description should be EBNF, not a parsed form of it.}}
<lang PicoLisp>(def 'expr 'ebnf '(term ((PLUS | MINUS) term) *))
"expr : term ( ( PLUS | MINUS ) term )* ;"
(def 'term 'ebnf '(factor ((MULT | DIV) factor) *))
"term : factor ( ( MULT | DIV ) factor )* ;"
(def 'factor 'ebnf '(NUMBER))</lang>
"factor : NUMBER ;" )

(for E EBNF
(use (@S @E)
(unless (and (match '(@S : @E ;) (str E)) (not (cdr @S)))
(quit "Invalid EBNF" E) )
(put (car @S) 'ebnf @E) ) )</lang>
<lang PicoLisp>(de matchEbnf (Pat)
<lang PicoLisp>(de matchEbnf (Pat)
(cond
(cond