antlr4: Sample doesn't work on Windows environment.

I was trying the first V4 example from the “Getting started page”. http://www.antlr.org/wiki/display/ANTLR4/Getting+Started+with+ANTLR+v4

Java files were generated and compiled but I have no success, because obtained “Can’t load Hello as lexer or parser” while calling TestRig.

http://screencast.com/t/LbFc7BcZU

C:\programming\Java\libraries\ANTLR 4.0>antlr4.bat Hello.g4
C:\programming\Java\libraries\ANTLR 4.0>java -cp antlr-4.0-complete.jar org.antlr.v4.Tool Hello.g4
C:\programming\Java\libraries\ANTLR 4.0>javac -cp antlr-4.0-complete.jar Hello*.java
C:\programming\Java\libraries\ANTLR 4.0>run Hello r -tree
C:\programming\Java\libraries\ANTLR 4.0>java -cp antlr-4.0-complete.jar org.antlr.v4.runtime.misc.TestRig Hello r -tree
Can't load Hello as lexer or parser

C:\programming\Java\libraries\ANTLR 4.0>dir
...

23.01.2013  00:28    <DIR>          .
23.01.2013  00:28    <DIR>          ..
22.01.2013  21:37         1 216 230 antlr-4.0-complete.jar
22.01.2013  21:38           554 786 antlr-4.0.tar.gz
22.01.2013  21:38           242 694 antlr-runtime-4.0.jar
23.01.2013  00:18    <DIR>          antlr4-4.0
23.01.2013  00:20                52 antlr4.bat
23.01.2013  00:25               235 Hello.g4
23.01.2013  00:31                31 Hello.tokens
23.01.2013  00:31               794 HelloBaseListener.class
23.01.2013  00:31               656 HelloBaseListener.java
23.01.2013  00:31             2 512 HelloLexer.class
23.01.2013  00:31             2 471 HelloLexer.java
23.01.2013  00:31                31 HelloLexer.tokens
23.01.2013  00:31               304 HelloListener.class
23.01.2013  00:31               258 HelloListener.java
23.01.2013  00:31               869 HelloParser$RContext.class
23.01.2013  00:31             3 026 HelloParser.class
23.01.2013  00:31             2 620 HelloParser.java
23.01.2013  00:24                68 run.bat
...

2013-01-23_0033


The content of grammar file I’ve just copy-pasted from web page.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 44 (17 by maintainers)

Most upvoted comments

I’m having a similar problem and can’t figure out what’s wrong. Help anyone? antlrerror

hahahah. no problem. Good luck!

I seem to get the same error as you. I run antlr4 command on Hello file, the Hello*.java files are created, I compile them, and when i run grun I get the message Can’t load Hello as lexer or parser. Any suggestions on how to fix this ? Hello.g4 has the grammar available on antlr website.