u/maanloempiain r/ProgrammingLanguages • Recommends
On “Anybody have tips for writing a Recursive Descent Parser for an AST? [ JS ]”
I wrote my first recdec parser by hand. It was a massive `switch` statement with countless `if`s checking wether the lookahead token was what the parser expected. At some point I could no longer understand anything I'd done.
I wouldn't recommend the following to just anyone, but it certainly made parsing _click_ for me: check out parser combinators. It's a functional pattern where you describe any language using tiny little functions that you combine (hence combinators) into bigger functions that describe productions in your grammar.
Here's a parser combinator tutorial that helped me a lot. It's in typescript though, but I would really urge anyone to use typescript over javascript.
[This…