A Path Less Taken

Breaking with convention in a very conventional fashion. Powered by WordPress

"What would you attempt to do if you knew you could not fail?"
Dr. Robert Schuller

Wednesday, November 4, 2009

Category: PHP Development Author: JJ 0 Comments

I have not posted in a while because I dropped into another science project. I was working on a little one off PHP app to use at work and I needed a small amount of data storage. I didn’t want to use MySQL because it’s not on my work computer and I wanted to make sure the data files were accessible to other applications by making them XML. I looked at several Text DB options (see the previous post), but none of them used XML to store their data. So, as I’m sure you guessed by now, I decided to roll my own. SCIENCE PROJECT!

Everything was going well until I tried to create a SQL parser for my simple SQL grammar. That’s when my inexperience at building Lexers and Parsers came into play. I looked around for a solution and came across the ANTLR Parser Generator. ANTLR (which stands for ANother Tool for Language Recognition) is the brain child of Terence Parr. It is a Lexical Analyzer and Parser rolled into one with a really nice grammar building tool called ANTLRWorks written by Jean Bovet.

ANTLR v3 uses the StringTemplate code generation template engine which makes it easier than in previous versions to define new target langauges. Unfortunately there is no mature implementation of a PHP target for me to use. I picked up a copy of Terence’s book “The Definitive ANTLR Reference” and have been reading it. This is giving me some useful guidance on how I can roll my own lexer and parser for my SQL grammar. It also has me thinking that I will have to take a stab at building my own grammar for some small langauge when I’m done with my science project. For those that missed it, that’s yet another science project. Cool!

Anyway, I’ll post on my progress as I try to wrap this exercise up in case anyone is interested. If you have an interest in building your own programming language or just want to learn more about how that is done then I recommend you give ANTLR a look. Terence has an obvious passion for this work and it shows in a well thought out and useful program that generates some very readable code.

No comments found. Please enter a comment if you have a question or contribution.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">