I’m wondering if Scalas/Haskells parser combinators are sufficient for parsing a programming language. More specifically the language MiniJava. I’m currently reading compiller construction and jflex and java cup is quite painful to work with so I’m wondering if I could/should use parser combinators instead.
The MiniJava syntax is very small.
MiniJavas BNF: http://www.cambridge.org/us/features/052182060X/grammar.html
I’m wondering if Scalas/Haskells parser combinators are sufficient for parsing a programming language. More
Share
Scala’s parser is a backtracking parser, so it can deal with pretty much any BNF or EBNF. It also means, though, that there are edge cases where input can be painfully slow to be read.
If the grammar can be changed into an LL(1) grammar, you can use the ~! operator to keep backtracking to a minimum.
The grammar probably CAN be turned into LL(1), but, as written, it is not. See, for instance, that Expression and Statement have First/First conflicts (look this up at the end of the linked article).
Anyway, for an academic project, it is enough. For real life compiler stuff, you’ll need faster parsers.