Since I’ve started thinking about DSLs I’ve picked up another book on my bookshelf Building Parsers with Java and leafing through it looking at how to actually build up a variety of languages using Java. As I was browsing through my Groovy user list I came upon a link to an active Java Parser called JParsec.
JParsec definitely looks interesting and they even have a Groovy extension that looks pretty slick.
Another interesting item that showed up in the Building Parsers book has to do with how he splits up language types. He defines them in the following way:
- Data language – this language is one that when parsed creates objects. Should be familiar to most, essentially most XML documents can be parked right here, or any kind of configuration like YAML.
- Logic language – this language that when parsed executes logic statements, helps to define the relationship between objects, such as business rules. Languages like Curry fall in this camp.
- Query language – this language provides the ability to query some kind of store, includes SQL, XPath, XQuery, etc.
- Expression language – this language consists of values, variables, operators and functions (often in a small and concise manner) that when executed yields a result. Regex and OGNL fall into this camp.
- Imperative language – A full blown language like Ruby or Java
- Engines – These are used by query and logic languages to interface with the data store or look through a variety of values and rules that might be needed by the logic language to execute its statements.
JParsec, is a rather odd parser. It feels like it was designed by a person who had never seen a Dragon book. Or maybe it is trying to solve different kind of cases.
I prefer ANTLR myself, which also has several language generators and even has a visual debugger to troubleshoot the grammar.