How can I get Lexer and Parser with ANTLR for C #?

ANTLR seems to support C #, but I don't know how I can generate a related class.

I searched and saw, there is an extension for Visual Studio, but I do not support 2015

So how can I generate Lexer and Parser for C # with ANTLR manually?

+4
source share
2 answers

No need to integrate with visual studio.

Download the jar file here: http://www.antlr.org/download/antlr-runtime-4.5.1.jar

Save it until C:\Test

Add the jar to your classpath:

System Properties Dialog Box> Environment Variables> Create or Add to CLASSPATH Variable

put C:\Test\antlr-runtime-4.5.1.jar , ;

C:\Test

, C:\Test

"outputdirectory" ( {outputdirectory} {input}:

java org.antlr.v4.Tool -o -visitor -no-listener -Werror -o {outputdirectory} -Dlanguage=CSharp {input}.g4
+2

VS . , (IIRC VS2015 ).

, Antlr4 NuGet, . ANTLR .

VS (, VS2013), ANTLR, .

, . , :

  • NuGet:

Install NuGet

  • , .g4

New text file

  • , :

Context menu

  • :

enter image description here

  • .g4 , "" " " Antlr4:

Assembly action

  • , :

    grammar MyLanguage;
    
    compileUnit: 'Hello' EOF;
    
  • File → Advanced Save Options UTF8 ISO-8859-1 (ANTLR UTF8 ):

Coding

  • ,

  • :

    var lexer = new MyLanguageLexer(new AntlrInputStream("Hello"));
    
+4

Source: https://habr.com/ru/post/1612680/


All Articles