This should be a good tutorial. I need to look into it:
http://www.ibm.com/developerworks/edu/os-dw-os-ecl-commplgin1.html
I know there is an excellent tutorial in Chinese. It demos how to craft a source code editor using Eclipse JFace Text Framework and a bit ANTLR. The link is here.
Here are some tutorial links for learning antlr v3:
- The Getting Started Tutorial from Official Site is Damn Good!
- ANTLR Works is a damn good tool!
- The Definitive Antlr Reference is a good book
- ANTLR 3.X Tutorials are good video course and introduced a damn good eclipse tool: ANTLR IDE.
After installing Ubuntu 9.10, eclipse became naughty. I tried to create a Java Project. However, mouse-click on Next/Finish buttons didn’t work. The buttons got focused, but no response. So you have to press ENTER or SPACE to actually press the buttons.
A quick fix here: create a shell script. For example, eclipse.sh:
export GDK_NATIVE_WINDOWS=1
/home/frankdu/Developer/eclipse/eclipse
Then add executable permission to the file: chmod +x ./eclipse.sh
Every time you run eclipse.sh to launch eclipse. At least we can be happy for a while. Please see http://www.eclipse.org/forums/index.php?t=msg&goto=498640& for more information.
We know that you can easily get the line numbers and column numbers information from the lexer token, via the properties: line & pos.
When facing an Abstract Syntax Tree (AST), the rules may be rewritten so that the tree node tokens are in different order. Then how to retrieve the line numbers?
This is very important in language execution, because users will definitely need information about which line caused the issue.
The answer is simple: Retrieve the information from underlying lexer tokens. In a tree grammar rule, there may be multiple tokens. So it’s up to you to decide which token to look into. A naive method may be to look into the first token of a tree node, using the start property.
There is another method. You can check it out at Recovering line and column numbers in your Antlr AST.
While writing code, programmers run into issue after issue. As examples, I will talk about the issues I encountered, and wish it may help others who run into similar issues. I wrote the program to monitor certain web pages. Therefore it should download web pages in correct encoding, in multi-threading environment. It should save the page to back-end database. The issues I encountered:
1. Threading issue
HttpClient from Apache is used as a web client. From their explanation page, we see no issue in the Multithreading section. There is no problem to run their multithreading example. However, you will run into problem if you create the HttpClient instance not in current Thread or it’s parent thread. This issue is not documented there, but very confusing to new users.
2. Implicit Dependency
I use Hibernate to persistent data, and maven 2 for dependency management. Maven 2 is awesome. However, what if some dependencies are missed out? Antlr v2.7.5H3 is for HQL parsing. However, Hibernate maven guide doesn’t statement it clearly. When you start to run HQL, the error will pop-up. Additionally, the antlr dependency is not available in official maven 2 repository. You will need to use the JBoss repository.
3. Session cache
After saving the data to database, another thread will take out the data for further processing. However, if you call getCurrentSession() on SessionFactory instance, you will get nothing. If you stopped the program, and run it again, you will get data from last run, but not data from new run. The issue is caused by the Session cache, which was designed for performance improvement. The solution is to call openSession() on the SessionFactory instance (or call openStatelessSession() if you hate cache).
I encountered other issues as well, such as encoding issue. However, the preceding issues are typical confusing issues.Why is software engineering so complicated?
It’s because people try to ask software to address the whole world, which is much more complicated.
Tire production can use assemble line, because the requirement is simple: I need a production for my Toyota car.
The car production can use assemble line, because the requirement is simple as well: I need a transportation tool from city A to city B, in land.
What if clients ask for a transportation vehicle to travel from any two point in a 3-dimension space? What if clients add the dimension of time?
People wish software to be capable of handling situations more intelligently, therefore people can be more lazy. There is nothing wrong here. But it can be an issue of feasibility, if the requirements have no boundary.
By default, the source level is 1.3 in maven 2. We need to config maven compiler to use Java 1.6. Add the following snippet to your pom:
-
-
<build>
-
<plugins>
-
<plugin>
-
<groupId>org.apache.maven.plugins</groupId>
-
<artifactId>maven-compiler-plugin</artifactId>
-
<configuration>
-
<source>1.6</source>
-
<target>1.6</target>
-
</configuration>
-
</plugin>
-
</plugins>
-
</build>
-
If you are doing antlr v3 for Java, you can be very interested in this series of video tutorials. It demos how to develop with antlr3 IDE, and also the process of a small language. It credits to Marcel for the recommendation. Check it out at:
The source code can be checked out with CVS or subversion. I assume that you are running eclipse. We will use the CVS tool.
1. Open the CVS view: Window -> Show View -> Other -> CVS -> CVS Repositories
2. Add a new repository location, using the settings below:
Host: dev.eclipse.org
Repository path: /cvsroot/eclipse
User: anonymous
Connection Type: pserver
Port: use default. If it doesn’t work or you are behind firewall, use 80.
And, that’s it! It should works now.