How can the PL/SQL grammar included with ANTLR4 be tested?

我是研究僧i 提交于 2020-01-13 20:35:06

问题


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

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
    ;

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

grun plsql sql_script -tree

But I get the following error:

Can't load plsql as lexer or parser

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.


回答1:


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.



来源:https://stackoverflow.com/questions/40691985/how-can-the-pl-sql-grammar-included-with-antlr4-be-tested

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!