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've never used Scala, but the existence of a definitive BNF makes this easy.
Trivially translated into Haskell's Text.ParserCombinators.Parsec:
goal = do c <- mainClass
cs <- many classDeclaration
eof
return $ c:cs
mainClass = do token "class"
name <- identifier
...
etc. The PArrows translation is pretty trivial too. You'll probably find it easier to have a distinct lexing phase before the parser, but you can do without too.
I'm using Scala's parser combinators to parse PL/SQL code, it works like a charm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With