EBNF syntax parser module
-
18-04-2021 - |
質問
Do you know of a syntax parser module (written in Ruby, Python, Javascript...) that, given a list of tokens and a EBNF-like grammar (passed as a simple string), returns the parsed tree? The closest I've found to this is SimpleParse, which is a nice library, but unfortunately it uses a single-step parsing (no tokenization). If possible I'd rather not use libraries in which the implementation is entangled with the language itself (pyparsing, treetop, ...).
I am not worried about the lexing/tokenization because there are a lot of libraries available (and even writing your own is pretty easy), but implementing a ENBF parser is not exactly a trivial task. I've checked the Python wiki LanguageParsing and tested some of them to no avail (maybe I overlooked the one I am looking for, there are so many...)
他のヒント
If you're familiar with Clojure at all I've found Instaparse to be great. You can write in "vanilla" EBNF as a multi-line string (or in a separate file and it even extends EBNF beyond context-free grammars into context sensitive grammars (though I haven't played around with that much).