Does grun only work with combined grammars?

528 views
Skip to first unread message

Roger Costello

unread,
Feb 10, 2015, 12:37:43 PM2/10/15
to antlr-di...@googlegroups.com
Hi Folks,

Below I show a lexer grammar and parser grammar. The parser grammar uses the tokenVocab feature to reuse the lexer grammar.

I ran antlr4.bat on the grammars and then compiled the Java programs. That worked fine. Then I tried running the test rig (grun.bat). I ran this command from the DOS prompt:

      grun Parser_To_Test_More_Command test -gui

and that generated this error:

      Exception in thread "main" java.lang.ClassCastException:
      class Parser_To_Test_More_Command 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)

I haven't had any success with running grun on non-combined grammars.

QUESTION: Does grun only work with combined grammars?


Note: I am using ANTLR 4.5
----------------------------------------------------------------------
        Lexer_To_Test_More_Command.g4
----------------------------------------------------------------------
lexer grammar Lexer_To_Test_More_Command ;

LQUOTE : '"'         -> more, mode(STR) ;

WS   : [ \t\r\n]+     -> skip ;

mode STR;

STRING : '"'     -> mode(DEFAULT_MODE) ;     // token we want the parser to see

TEXT : .         -> more ;

----------------------------------------------------------------------
       Parser_To_Test_More_Command.g4
----------------------------------------------------------------------
parser grammar Parser_To_Test_More_Command ;

options { tokenVocab=Lexer_To_Test_More_Command; }

test: STRING EOF ;

Terence Parr

unread,
Feb 10, 2015, 1:23:15 PM2/10/15
to antlr-di...@googlegroups.com
the names have to be TParser, TLexer.
T
> --
> 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/d/optout.

Roger Costello

unread,
Feb 10, 2015, 5:41:47 PM2/10/15
to antlr-di...@googlegroups.com
> the names have to be TParser, TLexer

Okay, I changed the names to TParser and TLexer. (Why did you recommend this? Is there a restriction on the length of file names? Are underscores not allowed in filenames?)

Nonetheless, the same error message is produced. Here are the commands I entered at the DOS command line:

antlr4 TLexer.g4
antlr4 TParser.g4
javac *.java
grun TParser test -gui

Here is the error that is generated:

Exception in thread "main" java.lang.ClassCastException: class TParser

        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)

What does that error message mean?

/Roger

Terence Parr

unread,
Feb 10, 2015, 6:59:07 PM2/10/15
to antlr-di...@googlegroups.com
Hi. T is name of combined grammar. use the suffixes when separate. test same though:

grun T test -gui

Ter
Reply all
Reply to author
Forward
0 new messages