Book error?

190 views
Skip to first unread message

Mister Bean

unread,
Mar 4, 2013, 3:05:52 AM3/4/13
to antlr-di...@googlegroups.com
I've run into this problem running the first example in the book:

After creating the Hello.g4 sample grammar (see next)

grammar hello; // define a grammar called 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, tables, newlines, \r (Windows) I generated and compiled the Java

I generated and compiled the Java code:

Hello.g4
Hello.tokens
HelloBaseListener.class
HelloBaseListener.java
HelloLexer.class
HelloLexer.java
HelloLexer.tokens
HelloListener.class
HelloListener.java
HelloParser$RContext.class
HelloParser.class
HelloParser.java

When I run grun from within the above directory, it gives an error message: "Can't load Hello as lexer or parser"

. . . . . . .

In addition, running grun with no parameters, does more than what the book says: It prints the usage messages *and* a NullPointerException stack trace:

TestRig.main ->
TestRig.process ->
java.lang.ClassLoader.loadClass ->
sun.misc.Launcher.$AppClassLoader.loadClass

I'm running on Windows 7 Ultimate x86, 4GB RAM, 8 cores.

What needs to be fixe? TIA

Hilco Wijbenga

unread,
Mar 4, 2013, 3:12:38 AM3/4/13
to antlr-di...@googlegroups.com
This example works fine for me (on Linux, though). Are you sure your
grun.bat is correct? And surely there is more to the stack trace than
you included?

Terence Parr

unread,
Mar 4, 2013, 12:45:10 PM3/4/13
to antlr-di...@googlegroups.com
Hi.  that is most likely a CLASSPATH issue. make sure the current directory is in the path.
Ter



--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.





--
Dictation in use. Please excuse homophones, malapropism, and nonsense. 
Reply all
Reply to author
Forward
0 new messages