如何测试 ANTLR4 中包含的 PL/SQL 语法? [英] How can the PL/SQL grammar included with ANTLR4 be tested?

查看:49
本文介绍了如何测试 ANTLR4 中包含的 PL/SQL 语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用 ANTLR,想尝试使用 plsql.g4 语法.我遵循 ANTLR v4 入门.

I'm just getting started using ANTLR, and want to try test parsing some simple PL/SQL statements using the plsql.g4 grammar. I am following the format used in Getting Started with ANTLR v4.

以下命令执行没有问题:

The following commands execute without issue:

antlr4 plsql.g4
java org.antlr.v4.Tool plsql.g4
javac plsql*.java

在入门示例中,他们运行以下命令:

In the getting started example, they run the following command:

grun Hello r -tree

其中Hello"是语法的名称,r"是其产生式规则之一.语法表明'sql_script'产生式规则由零个或多个单元语句或sqlplus命令组成,后跟输入流的结尾:

Where 'Hello' is the name of the grammar and 'r' is one of its production rules. The grammar indicates that the 'sql_script' production rule consists of zero or more unit statements or sqlplus commands followed by the end of the input stream:

sql_script
    : (unit_statement | sql_plus_command)* EOF
    ;

所以我试图像这样调用 PL/SQL 解析器:

So I am trying to invoke the PL/SQL parser like so:

grun plsql sql_script -tree

但我收到以下错误:

Can't load plsql as lexer or parser

调用此语法的解析器以生成简单 PL/SQL 语句的解析树的正确方法是什么?我在 Windows 机器上使用 JDK 8.这是一个屏幕截图,显示了我的终端窗口的内容.

What is the correct way to invoke the parser for this grammar to generate a parse tree for a simple PL/SQL statement? I am using JDK 8 on a Windows machine. Here is a screenshot showing the contents of my terminal window.

推荐答案

JVM 是罪魁祸首.在检查系统范围的 %CLASSPATH% 环境变量(如果存在)之前,它不会首先自动检查工作目录.添加一个."%CLASSPATH% 环境变量的开头将解决问题并允许命令按预期工作.请参阅 Windows 10 中编辑环境变量工具的此屏幕截图以了解其外观.

The JVM is the culprit. It does not automatically check the working directory first before checking the system-wide %CLASSPATH% environment variable if it exists. Adding a '.' to the beginning of the %CLASSPATH% environment variable will fix the problem and allow the command to work as intended. Refer to this screenshot of the Edit Environment Variable tool in Windows 10 to see how it should look.

可以通过控制面板->系统和安全->系统访问此工具,单击左侧的高级系统设置"项,然后单击标有环境变量"的按钮.选择一个变量,然后单击编辑..."按钮将在屏幕截图中显示该工具.

This tool can be accessed through Control Panel -> System and Security -> System, click on the item to the left that says "Advanced system settings", and then click on the button labeled "Environment Variables". Selecting a variable and then clicking the "Edit..." button will bring up the tool in the screenshot.

这篇关于如何测试 ANTLR4 中包含的 PL/SQL 语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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