Dashboard > ANTLR 3 > ... > ANTLR v3 documentation > Integration with Development Environments
  ANTLR 3 Log In | Sign Up   View a printable version of the current page.  
  Integration with Development Environments
Added by Terence Parr, last edited by Edgar Espina on Aug 12, 2008  (view change)
Labels: 
(None)

Table of Contents 


VisualStudio

C# Projects

For C# projects, you can integrate ANTLR with Visual Studio 2005 by pasting the following snippet of XML near the end of your .csproj file. Adjust the Included and OutputFiles to fit your project.

<ItemGroup>
    <Antlr3 Include="SimpleCalc.g">
      <OutputFiles>SimpleCalcLexer.cs;SimpleCalcParser.cs</OutputFiles>
    </Antlr3>
    <Antlr3 Include="BigCalc.g">
      <OutputFiles>BigCalcLexer.cs;BigCalcParser.cs</OutputFiles>
    </Antlr3>
  </ItemGroup>
  <Target Name="GenerateAntlrCode" Inputs="@(Antlr3)" Outputs="%(Antlr3.OutputFiles)">
    <Exec Command="java org.antlr.Tool -message-format vs2005 @(Antlr3)" Outputs="%(Antlr3.OutputFiles)"/>
  </Target>
  <PropertyGroup>
    <BuildDependsOn>GenerateAntlrCode;$(BuildDependsOn)</BuildDependsOn>
  </PropertyGroup>
</ItemGroup>

To finish off the integration, look higher in the same file and find the XML block that contains AssemblyInfo.cs:

<ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

  and add the additional Compile options below to have your .cs output files added to the project as dependent on your .g files.  Again, adjust the input and output names to fit your project.

<ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
        <Compile Include="SimpleCalcLexer.cs">
            <AutoGen>True</AutoGen>
            <DesignTime>True</DesignTime>
            <DependentUpon>SimpleCalc.g</DependentUpon>
        </Compile>
        <Compile Include="SimpleCalcParser.cs">
            <AutoGen>True</AutoGen>
            <DesignTime>True</DesignTime>
            <DependentUpon>SimpleCalc.g</DependentUpon>
        </Compile>
        <Compile Include="BigCalcParser.cs">
            <AutoGen>True</AutoGen>
            <DesignTime>True</DesignTime>
            <DependentUpon>BigCalc.g</DependentUpon>
        </Compile>
        <Compile Include="BigCalcLexer.cs">
            <AutoGen>True</AutoGen>
            <DesignTime>True</DesignTime>
            <DependentUpon>BigCalc.g</DependentUpon>
        </Compile>
  </ItemGroup>

With ANTLR 3.0, there are some minor integration issues. Sometimes error messages have an empty "location" string, so Visual Studio will not detect the error. Also, it is possible for ANTLR to generate the output file successfully even though your grammar has errors in it. When this happens, the grammar will not be recompiled until it is edited again (since the output is more recent than the grammar).

C/C++ .rules Files for Visual Studio

The C runtime distribution - use the 3.1 distribution, which you may need to get from the latest interim build at the time of writing - comes with a set of .rules files, which you can add in to your Visual Studio configuration. When you add a .g file to your Visual Studio project, it will ask you which rule file you wish to use. Note that you must tell Visual Studio whether this is a lexer only, parser only, parser+lexer, or tree grammar (you can change it later if you get this wrong).

The rulefiles are called:

antlr3lexer.rules
antlr3lexerandparser.rules
antlr3parser.rules
antlr3treeparser.rules

Right clicking on a .g file in solution explorer and selecting properties will allow you to configure any of the antlr command line options to suit your needs. The defaults are usually fine, but you may wish to configure the output and lib directories to conform to the usual layouts of directories that Visual Studio assumes, and -Xconversiontimeout is useful for more complicated grammars. The base directory will be the .vcproj directory and so your output may or may not be in this directory (do you store your .g files in the same directory as the .vcproj file basically).

The examples solution (C.sln), which is part of the downloadable examples tar/zip on the main ANTLR downloads page, uses this technique to build the ANTLR grammars, if you are looking for some examples. Look under the C subdirectory for the C target examples.

N.B.
These .rules files only work for the C target.


Eclipse

 Eclipse 3.3+ for Antlr 3.x

AntlrDT is a standard Eclipse plugin implementing an Antlr 3.1+ specific grammar editor, outline, and builder. Also includes a StringTemplate group file editor and outline view.

 See http://www.certiv.net/projects/plugins/antlrdt.html

ANTLR IDE. An eclipse plugin for ANTLRv3 grammars.

Features: Support ANTLR 3.1/3.0, advance text editor, grammar interpreter, documentation view, outline, builder, code generator, completation assistant.

ANTLR IDE 1.0.0 released. See http://antlrv3ide.sourceforge.net/

IntelliJ

NetBeans

Xcode

will follow...

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.1 Build:#806 May 06, 2007) - Bug/feature request - Contact Administrators