Lex and Yacc replacement


Is there a Rust version of lex and yacc (or bison and flex)?

Or how do people write parsers to be used with Rust? From scratch?

Any links to existing crates or any thoughts about the topic would be appreciated.


I don’t know of any direct ports, but there is quite some amount of parser crates that should fit your style:



My approach would be to first use one of the mentioned parsers to produce tokens (what flex does), and the use the same library to parse the token stream to produce an AST.

I’ve only used nom, which is generic over the input type, so you can use the default &[char] / &[u8] input type for the lexing, produce a Vec of tokens, and then use &[Token] as the input for the parser.

This approach works pretty well, and I’ve used it for years. Also in other languages with parser combinators like parsec (Haskell).


Lalrpop worked well for me (though I wish that someone wrote antlr backend for rust).


Interesting, I hadn’t thought of that. Thanks <3.


Thanks for your suggestion, that sounds very promising.


Thanks for the links. I will have a deeper look …