2
votes

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
I executed all the commands as you did and everything works! I manage to reproduce error when I deleted plsqlLexer.class file. Are you sure you execute the grun plsql sql_script -tree command in the directory where plsqlLexer.class and plsqlParser$*.class files are present?quepas
Yes. Here is a screenshot showing the contents of my terminal window.Dyndrilliac
On the screenshot : why all of the plsqlParser$*.class files listed with ls command are enclosed with single quotation marks '?quepas
@Quepas I'm not sure. I think it's just a quirk of Windows command prompt. If I use the same command in PowerShell, it displays them without the single quotes.Dyndrilliac

1 Answers

1
votes

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.