Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hello example not working on Windows after it has been split into separate lexer and parser #302

Closed
fraschfn opened this issue Jul 16, 2013 · 3 comments

Comments

@fraschfn
Copy link

I had the same issues as in this issue: #147 and the fix also worked for me.

I then tried to separate the lexer from the parser and I get an exception when I try to run the TestRig.

file HelloL.g4:

// Define a grammar called Hello
lexer grammar HelloL;

Hello : 'hello' ;
ID : [a-z]+ ;             // match lower-case identifiers
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines

file HelloP.g4:

// Define a grammar called Hello
parser grammar HelloP;

options { tokenVocab=HelloL; }

r  : Hello ID ;         // match keyword hello followed by an identifier

I then run these commands:

java -cp .;antlr-4.1-complete.jar org.antlr.v4.Tool HelloL.g4
java -cp .;antlr-4.1-complete.jar org.antlr.v4.Tool HelloP.g4

javac -cp .;antlr-4.1-complete.jar Hello*.java

java -cp .;antlr-4.1-complete.jar org.antlr.v4.runtime.misc.TestRig HelloP r -tree sample.txt

I then get this exception:

Exception in thread "main" java.lang.ClassCastException: class HelloP
        at java.lang.Class.asSubclass(Unknown Source)
        at org.antlr.v4.runtime.misc.TestRig.process(TestRig.java:159)
        at org.antlr.v4.runtime.misc.TestRig.main(TestRig.java:143)

Contents of sample.txt

hello parrt

These are the contents of the folder I work in (the batch files contain basically the commands above - but I also tested it directly in the shell):
image

@parrt
Copy link
Member

parrt commented Jul 16, 2013

Try

java -cp .;antlr-4.1-complete.jar org.antlr.v4.runtime.misc.TestRig Hello r -tree sample.txt

w/o the P.

Ter

@parrt parrt closed this as completed Jul 16, 2013
@fraschfn
Copy link
Author

I'm afraid it didn't work:

Can't load Hello as lexer or parser

Since I've split the file "Hello.g4" into "HelloL.g4" (lexer) "HelloP.g4" (parser)
there is no combined grammer "Hello" anymore, only a lexer (HelloL) and a parser (HelloP).

@parrt
Copy link
Member

parrt commented Jul 17, 2013

oh right. make it HelloLexer and HelloParser as the names of your items, including the filenames. please don't post questions here.

@parrt parrt reopened this Jul 17, 2013
@parrt parrt closed this as completed Jul 17, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants