question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't run example from getting started: "Can't load Hello as lexer or parser"

See original GitHub issue

https://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:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

17reactions
ghostcommented, Apr 8, 2016

I change .bat files and problem was solved:

@ECHO OFF
java org.antlr.v4.Tool %*
@ECHO OFF
SET TEST_CURRENT_DIR=%CLASSPATH:.;=%
if "%TEST_CURRENT_DIR%" == "%CLASSPATH%" ( SET CLASSPATH=.;%CLASSPATH% )
java org.antlr.v4.gui.TestRig %*

Is that a good solution?

4reactions
beardlybreadcommented, Apr 8, 2016

First guess would be that your current working directory (pwd) isn’t included in the CLASSPATH variable. It’s throwing a ClassNotFoundException here, so maybe try invoking java with -cp flag and explicitly define your path.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found