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.

1 Like

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 …

Sorry for digging up this old post, but I found the following project to be excellent:

It's exactly in the same spirit as lex/yacc, but for Rust.

If someone where to make it for Rust could that someone Please extend the LR parser with the possibility of indentation sensitive parsing? There is some post doc papers about that specifically and as far as I have read it should only be a constant factor in penalty for the runtime.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.