问题描述
似乎ANTLR支持C#语言,但我不知道如何生成相关类.
Seems ANTLR support C# language but I dont know how I can generate related class.
我搜索并发现存在Visual Studio扩展,但我不支持2015
I searched and saw exists an Extention for Visual Studio but I does not support 2015
那么,如何使用ANTLR手动为C#生成Lexer和Parser?
so How I can generate Lexer and Parser for C# with ANTLR manually ?
推荐答案
无需与Visual Studio集成.
No need for integration with visual studio.
在此处下载jar文件: http://www.antlr. org/download/antlr-runtime-4.5.1.jar
Download the jar file here: http://www.antlr.org/download/antlr-runtime-4.5.1.jar
将其保存到C:\Test
将jar添加到您的类路径中:
Add the jar to your classpath:
使用系统属性"对话框>环境变量>创建或附加到CLASSPATH变量
Using System Properties dialog > Environment variables > Create or append to CLASSPATH variable
在变量中,放入C:\Test\antlr-runtime-4.5.1.jar
如果该变量的值已经存在,则在新条目之前插入;
.
In the variable, put C:\Test\antlr-runtime-4.5.1.jar
If values already exist for this variable, insert a ;
before your new entry
将语法文件复制到C:\ Test
Copy in your grammar file to C:\Test
转到命令行,导航至C:\ Test
Go to the command line, navigate to C:\Test
创建"outputdirectory"文件夹,然后运行此文件夹(请记住要替换{outputdirectory}和{input}:
Create your 'outputdirectory' folder, and run this (remember to replace {outputdirectory} and {input}:
java org.antlr.v4.Tool -o -visitor -no-listener -Werror -o {outputdirectory} -Dlanguage=CSharp {input}.g4
这篇关于如何使用ANTLR for C#获得Lexer和Parser?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!