4

I'm looking for a parser generator for a reasonably complex language (similar in complexity to Python itself) which works with Python3. If it can generate an AST automatically, this would be a bonus, but I'm fine if it just calls rules while parsing. I have no special requirements, nor does it have to be very efficient/fast.

2 Answers 2

3

LEPL isn't exactly a parser generator - it's better! The parsers are defined in Python code and constructed at runtime (hence some inefficiency, but much easier to use). It uses operator overloading to construct a quite readable DSL. Things like c = a & b | b & c for the BNF c := a b | b c..

You can pass the results of a (sub-)parser to an abritary callable, and this is very usable for AST generation (also useful for converting e.g. number literals to Python-level number objects). It's a recursive descent parser, so you better avoid left recursion in the grammar (there are memoization objets that can make left recursion work, but "Lepl's support for them has historically been unreliable (buggy)").

Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately LEPL has been discontinued.
3

ANTLR can generate a lexer and/or parser in Python. You can also use it to create AST's and iterator-like structures to walk the AST (called tree grammars).

See ANTLR get and split lexer content for an ANTLR demo that produces an AST with the Python target.

7 Comments

ANTLR's python support library claims to be 2.x based, does it work with Python3?
Has a Linux and a Mac example on its front page and does not lose one word why it does not support the other 85% of Computers. Also, the documentation is payware.
@Nils, it also has a Windows example on the homepage. Sure, there are books you can buy, but there's plenty of good online material available to get started with ANTLR.
@Nils the start page's quick start tab has 3 small round buttons in the lower right corner: 1st is OSX, 2nd is Linux and the 3rd is Windows. You are right that this has been the same for more than a year. I will not argue with you about the other things you mention because it seems to me you're not really open to a normal discussion. And relating miss spelled words with code quality, really? Shall I compare the quality of your eye sight with your coding or research skills? Or would that be silly too?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.