[antlr-interest] dumbie question: Are there any examples ofbuilding antlr programs using different IDEs?

Jim Idle jimi at temporal-wave.com
Tue Oct 27 06:35:24 PDT 2009


The easiest way with Netbeans is to use a Maven build, which Netbeans has very good built in support for. That way you just configure where the .g files are and leave the rest to Maven, which will work both from the command line and from the IDE (not just Netbeans IDE either).

It takes a bit of learning, but to be honest, for a simple project, you can just copy an existing config. I (or someone) should really make a Maven project archetype (any volunteers?). But if you create a Maven project in Netbeans (in 6.7 this is File->New Project->Maven, then open the build.xml file, you can copy from this below (you will find lots of this is generic and the same as the build.xml that netbeans/maven creates for you. You just want the dependencies and the plugins.

Then read: www.antlr.org/antlr3-maven-plugin

There are lots of "5 minute intros to Maven" on the web.

The reason it is worth learning Maven is that aside from learning how to auto build .g files in to your Java stuff, it is a generic build tool and lots of projects use it, so it is not ANTLR or IDE specific.

Jim


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.temporalwave</groupId>
    <artifactId>tsql2005</artifactId>
    <packaging>jar</packaging>
    <version>1.0</version>
    <name>Temporal Wave T-SQL 2005 Grammar</name>
    <url>http://www.temporal-wave.com/tsql</url>

    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.antlr</groupId>
            <artifactId>antlr-runtime</artifactId>
            <version>3.2</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>

        <defaultGoal>install</defaultGoal>

        <plugins>

            <plugin>
                <groupId>org.antlr</groupId>
                <artifactId>antlr3-maven-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <conversionTimeout>10000</conversionTimeout>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>antlr</goal>
                        </goals>
                    </execution>
                </executions>

            </plugin>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            
            <plugin>

                <!--

                    Build an uber-jar that is packaged with all the other dependencies,
                    such as the antlr-runtime and stringtemplate etc. This will be useful
                    for developers, who then do not need to download anything else or
                    remember that they need antlr.jar in their CLASSPATH and so
                    on.

                  -->

                <artifactId>maven-assembly-plugin</artifactId>

                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <!--

                        Specify that we want the resulting jar to be executable
                        via java -jar, which we do by modifying the manifest
                        of course.
                      -->
                    <archive>

                        <manifest>
                            <mainClass>test.Main</mainClass>
                        </manifest>
                    </archive>

                </configuration>

                <!--

                    We don't want to have to specifically ask for the uber jar, so we attach the
                    running of this plugin to the execution of the package life-cycle
                    phase.
                  -->
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attached</goal>
                        </goals>
                    </execution>
                </executions>

            </plugin>



        </plugins>

    </build>
</project>





> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Graham Wideman
> Sent: Tuesday, October 27, 2009 1:55 AM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] dumbie question: Are there any examples
> ofbuilding antlr programs using different IDEs?
> 
> Raymond,
> 
> The matter of using Antlr to generate java files for parser or lexer
> can be separated from the matter of using your IDE.  You can run antlr
> from the command line, using whatever kind of grammar file (lexer,
> combined, parser, tree) and tell it to send the output (java) files to
> the directory of your choice. That can be a directory that's within a
> project as set up by your IDE, and thus can be referenced (called) by
> other files in your project. (You may need to prod the IDE to refresh
> its knowledge of the files when you change them like this.)
> 
> With that arrangement, you don't have to learn how to get the IDE's
> build system to run external programs, though usually that's not too
> involved and not particularly special for antlr. Of course, not having
> the IDE automatically run antlr means you have to do that step manually
> when you change the grammar, but at least it gets you started. Also you
> then know what's supposed to happen, so that when you do automate it
> you'll know that it is or isn't working properly.
> 
> >From another angle, your choice of IDE should be driven by other
> considerations within your project or larger development process, not
> by whether there's an incremental learning effort for automating antlr:
> even if that effort is too much at present, you can put that off by
> running antlr manually.
> 
> -- Graham
> 
> 
> At 10/26/2009 11:26 PM, Jacob, Raymond CIV SPAWARSYSCEN-ATLANTIC,
> wrote:
> >I have a dumbie question regarding where can I find examples of how
> >to build an antlr program using different IDEs?
> >
> >
> >Background: I am not a java programmer.
> >I have read part of the antlr book by Terrence Parr.
> >I think I have gotten as far as the Chapter that use STL to build
> >programs. I can not
> >remember the exact chapter because I don't have the book
> >in front of me.
> >I did not say I understood everything in the book.
> >I think I understand a few of the examples.
> >
> >An intern with more brain cells than I have left was developing
> >a program using netbeans. So I thought I would give netbeans a
> >try. That was about 5 months ago and I still have not figured
> >out how to use netbeans to build a grammar with like the examples
> >in the book. For instance, I can not figure out how to get the
> >IDE to use a separate file for a lexer-the file with the tokens
> instead
> >putting
> >all the tokens and the grammar in one file. As far as I can tell
> >in order to build a grammar in netbeans I need to know ant
> >and modify the build.xml to add the plug-in for antlr in netbeans.
> >
> >I realize now that I would have been further along if I had
> >just used the command line instead of an IDE. But what has
> >not been done is done.
> >
> >Question: Are there any IDEs that make it easy or natural to
> >build programs using the code in the Antlr reference
> >book? i.e. I want to focus on the code in the book and not the IDE.
> >
> >If there are not any IDEs for the IDE challenged,
> >are there any examples of building antlr programs using different
> IDEs?
> >
> >I apologize in advance for my ignorance.
> >When I searched the list my Google-fu was weak and I could not find
> >anything relevant.
> >
> >Thank you again
> >rjjr
> >
> >
> >
> >
> >List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >Unsubscribe:
> >http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address





More information about the antlr-interest mailing list