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

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

问题描述

我刚开始使用ANTLR,并且想尝试使用 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天全站免登陆