ANTLR 3.x Tutorial

A video tutorial on ANTLR 3.x

Many folks have asked me to convert my ANTLR 2.x tutorial to ANTLR 3.x. I started doing it and got reaaaaaaaaaalllly tired of typing. Being a bear of very little patience, I decided to go a different route, one which I think will prove even more effective. Go laziness!

This version of the tutorial is video-based. Using Camtasia (the best screen/video capture software in the world!) I’ve recorded my babbling on while creating a parser for the XL language in ANTLR 3.x in Eclipse.

Videos

I’ve uploaded the following videos to vimeo. Each is listed below with a short description. I recommend you watch them in order as they assume knowledge of previous videos.

Vimeo video group: http://vimeo.com/groups/29150

Video License

Creative Commons License
ANTLR 3.x Tutorial by Scott Stanchfield is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.

Feel free to watch the videos and point friends to them, but you cannot use them as part of any commercial product nor can you create derivative works. Follow the link above to see the complete license text.

Concepts - What I should have recorded first but forgot until I was 6 steps in…

Prologue - Getting Eclipse set up for ANTLR 3.x development

Part A: Setting up ANTLR 3.x in Eclipse 3.5

Part B: Creating and Executing a Grammar in Eclipse

Creating an XL Recognizer

Part 1: Starting to implement XL

Part 2: Let’s check out the generated code

Part 3: Parsing expressions

NOTE: I noticed I messed up the expression tree a bit. That’s what I get for doing this on the fly ;) The tree for 3+2*6+4 should look like

                     +
                   / \
                  +   4
                 / \
                3   *
                   / \
                  2   6

Part 4: Ifs, loops, and comments

Part 5: Procedures and Functions

Part 6: Type declarations, scanner fragments, cleaning up

Interpreting Expressions

Part 7: Interpreting expressions while parsing the input

Part 8: Interpreting expressions using the GoF Interpreter Pattern

Part 9: Interpreting expressions using an ANTLR Tree Parser

Sample Code

The following are snapshots of the sample code at various points during the tutorial.

Software License

All sample code is licensed under the Eclipse Public License, version 1.0.

See http://www.eclipse.org/legal/epl-v10.html for details.

ANTLR itself is licensed under a BSD License:

ANTLR 3 License

[The BSD License] Copyright (c) 2003-2008, Terence Parr
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.