(filtered by month 'April 2010')

Generating ANTLR classes from Ant

Added: April 29, 2010

Tags: ANTLR DSL book hint

I am in the middle or reading Domain Specific Languages by Martin Fowler and I have started to experiment with ANTLR today. After copy&pasting of example and fixing a few problems I wanted to generate a parser from grammar. I wanted to use following Ant snippet taken from Ant documentation (Rough Cuts of the book does not show how to do that):

	<target name="generate" depends="prepare">
		<antlr target="${dir.antlr.src}/Greetings.g" outputdirectory="${dir.gen}" />
	</target>
But regardless of my experiments ANTLR process invoked from Ant always ended with Unable to determine generated class. Googling did not help. I found many questions, but no solution. Finally I settled on a following workaround, based on standalone generation of sources from the grammar:
	<target name="generate" depends="prepare">
		<java jar="lib/antlr-3.2.jar" fork="true">
			 <arg value="-o"/>
			 <arg value="${dir.gen}"/>
			 <arg value="${dir.antlr.src}/Greetings.g"/>
		</java>
	</target>
This does the trick. Now back to the example to see what it does.

Domain Specific Languages

Added: April 28, 2010

Tags: DSL book

Long awaited book Domain Specific Languages By Martin Fowler have finally got to Rough Cuts stage at Safari Books Online. I've started to read it immediately. I've just finished narratives part and now I am getting into reference material (I am one of those who read it cover to cover even it is not expected). So far I have enjoyed it and my expectations are still high.

I have done some small DSLs in the past, mostly for using in unit and system tests and I enjoy using fluent interfaces of mocking libraries. I can say I have done also some code generation on project for previous employer. But all of them were quite informal. That's the reason I like this book - it gives me an overall view, it helps to transform my former experiences into coherent bulk of knowledge. It should help me to understand WHY, and WHEN so that I can spot possible applications easier. HOW is also useful, it can save a lot of time when exploring possible solutions.

Unfortunately I think majority of programmers will not try to read this book, because its topic is too far from their interest and experiences. But maybe the book will help to spread awareness of DSL usefulness. I guess there are not many programmers these days who are not using some kind of DSL, be it SQL, CSS, mocking library, ...