This post originated from an RSS feed registered with Java Buzz
by Weiqi Gao.
Original Post: Mark Volkmann: An Introduction To ANTLR v3
Feed Title: Weiqi Gao's Weblog
Feed URL: http://www.weiqigao.com/blog/rss.xml
Feed Description: Sharing My Experience...
Last Friday, Mark Volkmann presented a tutorial on ANTLR v3 at the OCI internal Java lunch. Since Mark has posted his presentation slides out on the internet, I did not take my usual amount of notes.
For me, ANTLR has been something that I'm aware of for a long time. I may have encountered it before it became ANTLR (PCCTS) when it was C++ based. However, its lack of applicability in everyday programming and the terseness of the documentation meant that I never get to know it well enough to actually use it in production code. The situation changed last year when the Pragmatic Bookshelf published the The Definitive ANTLR Reference book.
I have been staring at my copy of the book for a few months waiting for the time when I would have a big chunk of time to start reading and experimenting with it. Mark's talk gave me enough of a push to start my experimentation with ANTLR v3. Hopefully, this time I can sustain my energy and finish the book.
And one particularly good thing about Mark's talk is that its accompanied by a couple of examples that I can play with. Here's what the example does:
[weiqi@gao Math]$ java -jar build/math.jar
math> f(x) = x^2 - 3x + 2
math> print f()
f(x) = x^2 - 3x + 2
math> print f'()
f'(x) = 2x - 3
math> print f(3)
2.0
math> help
In the help below
* fn stands for function name
* n stands for a number
* v stands for variable
To define
* a variable: v = n
* a function from a polynomial: fn(v) = polynomial-terms
(for example, f(x) = 3x^2 - 4x + 1)
* a function from adding or subtracting two others: fn3 = fn1 +|-ghg fn2
(for example, h = f + g)
To print
* a literal string: print "text"
* a number: print n
* the evaluation of a function: print fn(n | v)
* the defintion of a function: print fn()
* the derivative of a function: print fn'()
* multiple items on the same line: print i1 i2 ... in
To list
* variables defined: list variables
* functions defined: list functions
To get help: help or ?
To exit: exit or quit
If you've been trying to get to know a little bit about ANTLR but never have the right incentive or courage to open the book, give Mark's presentation material a try. And if you are in the St. Louis area, Mark will be giving the same presentation at the NFJS conference in March and the St. Louis Java Users Group in June.