DEV Community

Discussion on: The Coolest Programming Language Features

Collapse
 
renegadecoder94 profile image
Jeremy Grifski

Wait, so you can write an entire language grammar in Haskell like that?! I once wrote a compiler in java, and I ended up just using ANTLR to generate the syntax tree (and a huge string of If statements to clean up that tree). This would have been a lot more fun to work with.

Collapse
 
vicentemaldonado profile image
Vicente Maldonado • Edited

Yes it's from the parser generator example

haskell.org/happy/doc/html/sec-usi...

I understand you can do the same in OCaml and F#, they say ML languages are well suited for compiler construction for that. I've been playing with yacc-like Java parser generators and that seems such a time saver compared to a Java class hierarchy.

Edit: you still have to define production rules though, just like in Yacc.