如何使用 ANTLR for C# 获得 Lexer 和 Parser? [英] How can I get Lexer and Parser with ANTLR for C#?

查看:32
本文介绍了如何使用 ANTLR for C# 获得 Lexer 和 Parser?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎 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# 生成词法分析器和解析器?

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆