Giter Site home page Giter Site logo

antlr4cs's Introduction

C# target for ANTLR 4

Introduction

This document gives a basic overview of using the C# target for ANTLR 4 with C# projects in Visual Studio.

Available Targets

This target provides several C# targets, numbered according to the target framework version. When the grammars are generated by Antlr4.targets as part of the build, the code generation target will be automatically selected to match the TargetFrameworkVersion property in the project file.

Target Name Runtime Library .NET Framework Version C# compiler version
CSharp_v4_5 Antlr4.Runtime.v4.5.dll .NET 4.5 C# 3+ (Visual Studio 2008+)
CSharp_v4_0 Antlr4.Runtime.v4.0.dll .NET 4.0 C# 3+
CSharp_v3_5 Antlr4.Runtime.v3.5.dll .NET 3.5 C# 3+
CSharp_v3_0 Antlr4.Runtime.v2.0.dll (same as below) .NET 3.0 C# 3+
CSharp_v2_0 Antlr4.Runtime.v2.0.dll .NET 2.0 C# 3+

Visual Studio Support for ANTLR 4 Grammars

Currently there is no Visual Studio extension specifically designed for editing ANTLR 4 grammars. However, now that a C# target for ANTLR 4 is available an editor should be available in the "reasonably near" future. If this feature is particularly important to your team, Tunnel Vision Labs' Sponsored Development Program may be a cost effective option for reducing the release timeframe.

Base Project Layout

C:\dev\CoolTool\
  CoolProject\
    CoolProject.csproj
  CoolTool.sln

Adding ANTLR to the Project Structure

  1. Download the current C# release from the following location: TODO
  2. Extract the files to C:\dev\CoolTool\Reference\Antlr4

After these steps, your folder should resemble the following.

C:\dev\CoolTool\
  CoolProject\...
  Reference\
    Antlr4\
      Antlr4.targets
      Antlr4BuildTasks.dll
      antlr4-csharp-[version]-complete.jar
  CoolTool.sln

MSBuild Support for ANTLR

Since the steps include manual modification of the Visual Studio project files, I very strongly recommend you back up your project (or commit it to source control) before attempting these steps.

  1. Open the CoolTool.sln solution in Visual Studio

  2. Unload the CoolProject project by right-clicking the project in Solution Explorer and selecting Unload Project

  3. Open CoolProject.csproj for editing by right-clicking the unloaded project in Solution Explorer and selecting Edit CoolProject.csproj

  4. For reference, locate the following line

     <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets"/>
    

    Note: the line appears as follows in some projects

     <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
    
  5. After the line in step 4, add the following code

     <PropertyGroup>
       <!-- Folder containing Antlr4BuildTasks.dll -->
       <Antlr4BuildTaskPath>$(ProjectDir)..\Reference\Antlr4</Antlr4BuildTaskPath>
       <!-- Path to the ANTLR Tool itself. -->
       <Antlr4ToolPath>$(ProjectDir)..\Reference\Antlr4\antlr4-csharp-4.0.1-SNAPSHOT-complete.jar</Antlr4ToolPath>
     </PropertyGroup>
     <Import Project="$(ProjectDir)..\Reference\Antlr4\Antlr4.targets" /> 
    
  6. Save and close CoolProject.csproj

  7. Reload the CoolProject project by right-clicking the project in Solution Explorer and selecting Reload Project

Adding a Reference to the C# Runtime

In the CoolProject project, add a reference to Antlr4.Runtime.dll, which is located at C:\dev\CoolTool\Reference\Antlr4\Antlr4.Runtime.dll.

Grammars

TODO

Custom Token Specifications (*.tokens)

TODO

Generated Code

TODO

Extra Features in the C# Target

TODO

Example Grammars

TODO

antlr4cs's People

Contributors

sharwell avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.