Can't run example from getting started: "Can't load Hello as lexer or parser"
See original GitHub issuehttps://github.com/antlr/antlr4/blob/master/doc/getting-started.md
Microsoft Windows [Version 10.0.10586]
(c) Корпорация Майкрософт (Microsoft Corporation), 2015. Все права защищены.
> type bin\antlr4.bat
java org.antlr.v4.Tool %*
> type bin\grun.bat
java org.antlr.v4.gui.TestRig %*
> java org.antlr.v4.Tool
ANTLR Parser Generator Version 4.5.3
-o ___ specify output directory where all output is generated
-lib ___ specify location of grammars, tokens files
-atn generate rule augmented transition network diagrams
-encoding ___ specify grammar file encoding; e.g., euc-jp
-message-format ___ specify output style for messages in antlr, gnu, vs2005
-long-messages show exception details when available for errors and warnings
-listener generate parse tree listener (default)
-no-listener don't generate parse tree listener
-visitor generate parse tree visitor
-no-visitor don't generate parse tree visitor (default)
-package ___ specify a package/namespace for the generated code
-depend generate file dependencies
-D<option>=value set/override a grammar-level option
-Werror treat warnings as errors
-XdbgST launch StringTemplate visualizer on generated code
-XdbgSTWait wait for STViz to close before continuing
-Xforce-atn use the ATN simulator for all predictions
-Xlog dump lots of logging info to antlr-timestamp.log
> java -version
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
> javac -version
javac 1.8.0_77
> type Hello.g4
// Define a grammar called Hello
grammar Hello;
r : 'hello' ID ; // match keyword hello followed by an identifier
ID : [a-z]+ ; // match lower-case identifiers
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines
> echo %CLASSPATH%
C:\Users\ploskov\Documents\Javalib\antlr-4.5.3-complete.jar;C:\Users\ploskov\Documents\Javalib\antlr-runtime-4.5.3.jar
> antlr4 Hello.g4 && dir
> java org.antlr.v4.Tool Hello.g4
Том в устройстве C не имеет метки.
Серийный номер тома: 2257-E72E
Содержимое папки C:\Users\ploskov\Documents\tmp
08.04.2016 21:10 <DIR> .
08.04.2016 21:10 <DIR> ..
08.04.2016 21:07 241 Hello.g4
08.04.2016 21:10 31 Hello.tokens
08.04.2016 21:10 1 353 HelloBaseListener.java
08.04.2016 21:10 3 236 HelloLexer.java
08.04.2016 21:10 31 HelloLexer.tokens
08.04.2016 21:10 554 HelloListener.java
08.04.2016 21:10 3 707 HelloParser.java
7 файлов 9 153 байт
2 папок 672 314 544 128 байт свободно
> javac Hello*.java
> dir
Том в устройстве C не имеет метки.
Серийный номер тома: 2257-E72E
Содержимое папки C:\Users\ploskov\Documents\tmp
08.04.2016 21:12 <DIR> .
08.04.2016 21:12 <DIR> ..
08.04.2016 21:07 241 Hello.g4
08.04.2016 21:10 31 Hello.tokens
08.04.2016 21:12 794 HelloBaseListener.class
08.04.2016 21:10 1 353 HelloBaseListener.java
08.04.2016 21:12 3 356 HelloLexer.class
08.04.2016 21:10 3 236 HelloLexer.java
08.04.2016 21:10 31 HelloLexer.tokens
08.04.2016 21:12 304 HelloListener.class
08.04.2016 21:10 554 HelloListener.java
08.04.2016 21:12 869 HelloParser$RContext.class
08.04.2016 21:12 4 160 HelloParser.class
08.04.2016 21:10 3 707 HelloParser.java
12 файлов 18 636 байт
2 папок 672 314 523 648 байт свободно
> grun Hello r -tree
> java org.antlr.v4.gui.TestRig Hello r -tree
Can't load Hello as lexer or parser
What I did wrong? (without antlr-runtime-4.5.3.jar I have same behavior)
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
antlr4-Can't load Hello as lexer or parser - Stack Overflow
Windows. Go to the start menu and search for Environment Variables and you will find Set Environment Variables for Users or something like...
Read more >antlr 4 Can't load as lexer or parser - Google Groups
This is a little old now but the cause is that the lexer/parser files generated by Antlr have not been compiled. You've probably...
Read more >Java – antlr 4 Can't load as lexer or parser – iTecNote
I'm using antlr 4 to write my grammar. I would like to see the gui three generated by my grammar. When I try...
Read more >Getting Started (Hello World) | Antlr - Datacadamia
Can't load Hello as lexer or parser ... This is because the lexer and parser generated class file are not in the classpath....
Read more >ANTLR Magic — Developing Mainframe Language ... - Medium
For example: Hibernate uses ANTLR for parsing and processing HQL queries ... Parser rule names must start with a lowercase letter and lexer...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I change .bat files and problem was solved:
Is that a good solution?
First guess would be that your current working directory (
pwd
) isn’t included in theCLASSPATH
variable. It’s throwing aClassNotFoundException
here, so maybe try invoking java with-cp
flag and explicitly define your path.