My project for this semester is creating an ANTLR based Processing to JavaScript converter.
Basically, I’m using ANTLR v3 to create a tool that translates Processing code into JavaScript.
The Processing.js project is working on porting Processing to JavaScript. Currently, it utilizes a series of regular expressions in order to parse the code into JavaScript. However, as Dave puts it, this current method is brittle.
There is an ANTLR v2 based Java grammar that translates Processing to Java. When ANTLR v3 came out, it had JavaScript added as a new target language (a language it could translate to), enabling ANTLR to translate languages to JavaScript. The JavaScript target is still in beta state. It has a few bugs, but is passing many test suites. Short-term, the regular expression parser will work out. Long-term, a stand-alone converter based on ANTLR would be nicer. What I’ll be doing this semester is writing the grammar (the set of rules) needed to translate Processing to JavaScript, thus creating the converter.
If you’d like a peek, here is THE BUG Dave filed.
I have chosen this project because I want to do something for the Processing for the Web project. I am interested in where Processing.js is going. I find that I like the Processing language on a personal level (it programs graphics!), and it has found a little space in my heart. I am also interested in learning about grammars, dusting of my JavaScript skills, and I like the word ANTLR (Both Jeff and Mike saw that one coming). I have decided that if Processing wants an ANTLR based JavaScript grammar, then I want it to have one.
I am about to spend this semester figuring out what it will take to produce this grammar.
The Process:
My work can be tracked via this fantabulous project page on the CDOT wiki.
As things progress, comments may appear on lighthouse, where Dave filed THE BUG.
I will also be updating this blog as I proceed.
The Timeline:
0.1 Release – Feb 19th, 2010
0.2 Release – Mar 19th, 2010
0.3 Release – Apr 9th, 2010All of these days are Fridays. 11:59pm is the latest I can submit each release before it’s counted as late. Check out my blog. When things are going well, expect earlier releases.
0.1 Release
For the first release I intend to have the ANTLR grammar able to translate variables from Processing into JavaScript. The reason this is so basic is that I have approximately 20 days between today and the 0.1 release to learn ANTLR, familiarize myself with ANTLRWorks (ANTLR’s grammar development environment), dust off my Java and JavaScript skills and write the first piece of this grammar. It is possible that I could finish early. If this is the case, I will start pulling tasks out of the 0.2 release and including them with 0.1.
Translating variables would make an excellent starting point for this project. Once I succeed in getting a piece of the ANTLR grammar working, the rest should come along with a little time and effort.
0.2 Release
(To be updated while I learn ANTLR during the beginning of the 0.1 release)
I believe I’ll be writing 2 grammars. One for a lexer and one for a parser. Here’s the big problem. Until I get more into ANTLR and writing grammars … this section is going to be a little blank.
I’m in the middle of the ANTLR Translator Generator FAQ From jguru. I’m reading ‘an overview of ANTLR and how to approach building things with it’. I’m not totally hopeless.
Any update to this section will be posted on the Project Page.
0.3 Release
This release will have that nice little ANTLR based JavaScript grammar for Processing.
PDE (Processing Development Environment), Bespin, and Eclipse should be able to “compile Processing for the web”. =)
Things I’ll Be Learning:
ANTLR and ANTLRWorks
- ANTLR may take a bit of time and the best place to practice it is probably by using it’s grammar development environment, ANTLRWorks. At least for the purpose of practicing examples from Terence Parr’s ANTLR reference books (more on those in a sec), and examples from the wiki. Unfortunately, ANTLR’s JavaScriptTarget isn’t integrated into ANTLRWorks yet.
Processing and the PDE
- I know nothing of Processing, but I like what I’ve seen from it. I’ll learn it so I can translate it to JavaScript. Excited.
Refreshing my Java and JavaScript
- I need the JavaScript because it’s my target language. I must know how it works. I need Java because Terence’s reference books, and a large majority of the examples, were written for ANTLR’s Java target. I need it to learn ANTLR.
I Plan to Learn ‘em with these Resources:
I’m going to be all over antlr.org (especially the FAQ and documentation) and Processing.org/learning/.
Besides a few class readings I need to catch up on,
this blog is going to be about learning Processing and ANTLR v3.
The best way to learn ANTLR is from Terence Parr himself. He has 2 books out:
- The Definitive ANTLR Reference: Building Domain-Specific Languages
- Language Implementation Patterns: Create Your Own Domain-Specific and General Programming Languages
The second book came out Dec 31, 2009, just in time! Apparently, the first book (noted as being an excellent resource) is easier to grasp once parts of the second book is read.
Supplement the books with examples from ANTLR’s wiki (for examples in target languages other than Java) and ANTLR’s two mailing lists: ANTLR-[interest] and ANTLR-[dev], and I should be good to go. I hope.
I’ve been looking high and low for ANTLR’s IRC channel. Does it exist? If anyone knows where the ANTLR developers are on IRC, I’d love to do some lurking.
Contacts:
None. Contacting someone now would only waste their time.
Since I am completely new to ANTLR and its dev environment, I need to familiarize myself with it before I can ask any feasible questions. My 0.1 release requires a lot of learning. Shortly before its release, I should have a much clearer picture of what I am dealing with, and I will be able to ask some good questions. Until then, I will be sitting down with ANTLR, learning in small steps.
First, I must RTFM.
Any update to this section will be posted to the Project Page.
Collaboration:
My code will need to be tested on PDE (Processing Development Environment), Bespin and Eclipse once I’ve got the grammar going.
The grammar needs to be tested to ensure it translates functions properly. Anyone who would like to try breaking it is welcome.
Contribution:
Since this project will require me to brush up on my Java and JavaScript, as well as learn some Processing, I would be up for testing or debugging in these languages. I’m also good for any tasks that may be deemed ‘boring’. I’m not easy to bore.
Talk to me.
Barriers and Risks:
Learning ANTLR3JavaScriptTarget, which is still in beta state.
- It has poor documentation, isn’t integrated with ANTLRWorks yet, the -debug option is unavailable, and I’m told to expect bugs and problems.
Fix: the Java target API Documentation will suffice for now, the rest I have to figure out as I go.
My learning style, which is very systematic.
- I will be hesitant to start on any code until I have thoroughly researched my topics (ANTLR, ANTLRWorks, Java, JavasScript, grammars). I like (and will be tempted) to read entire books/webpages on the subject before starting. I know I cannot approach the project in this way.
Fix: I need to tweak the way I usually learn. I only need to learn enough code to solve the problem. Use indexes, and tables of contents. (This is the only risk I could control).
ANTLR3JavaScriptTarget isn’t integrated with ANTLRWorks.
- I’ll need ANTLRWorks to help me work my way through examples, etc. However, when it actually comes to my grammar, ANTLRWorks won’t be of much use.
Fix: … hum. I guess ANTLRWorks will be temporarily reduced to being a regular text editor.
Nicely written. Well done.
Did you get ANTLR even generating using the JavaScriptTarget with the default build?
Hi Paul,
Sorry it took so long to answer you.
I’m working on getting ANTLR generating with the JSTarget.
If you haven’t already got it working, check this out:
http://code.google.com/p/antlr-javascript/wiki/BuildingANTLRJavaScriptTarget
Let me know how that goes. If it works out, I’ll be blogging about it.
[...] Last time, I had a few barriers. This time I only have one. I’m afraid that this project will end up like the ANTLR one and not be completed. Last time, I got stuck and I gave up. Given how often you’re supposed to get stuck when working in Open Source, I have a feeling this threat is going to loom over my head the entire semester. [...]