Always token recognition errors

4,482 views
Skip to first unread message

Philipp Nies

unread,
May 21, 2014, 3:25:18 AM5/21/14
to antlr-di...@googlegroups.com
Hello,

since a few days I'm experimenting with ANTLR and I receive even with an easy grammar like the one mentioned below many errors.

grammar test;

addition: '2' '+' '2';

 line 1:0 token recognition error at: 'g'
line 1:1 token recognition error at: 'r'
line 1:2 token recognition error at: 'a'
line 1:3 token recognition error at: 'm'
line 1:4 token recognition error at: 'm'
line 1:5 token recognition error at: 'a'
line 1:6 token recognition error at: 'r'
line 1:7 token recognition error at: ' '
line 1:8 token recognition error at: 't'
line 1:9 token recognition error at: 'e'
line 1:10 token recognition error at: 's'
line 1:11 token recognition error at: 't'
line 1:12 token recognition error at: ';'
line 1:13 token recognition error at: '\r'
line 1:14 token recognition error at: '\n'
line 2:0 token recognition error at: '\r'
line 2:1 token recognition error at: '\n'
line 3:0 token recognition error at: 'a'
line 3:1 token recognition error at: 'd'
line 3:2 token recognition error at: 'd'
line 3:3 token recognition error at: 'i'
line 3:4 token recognition error at: 't'
line 3:5 token recognition error at: 'i'
line 3:6 token recognition error at: 'o'
line 3:7 token recognition error at: 'n'
line 3:8 token recognition error at: ':'
line 3:9 token recognition error at: ' '
line 3:10 token recognition error at: '''
line 3:12 token recognition error at: '''
line 3:13 token recognition error at: ' '
line 3:14 token recognition error at: '''
line 3:16 token recognition error at: '''
line 3:17 token recognition error at: ' '
line 3:18 token recognition error at: '''
line 3:20 token recognition error at: '''
line 3:21 token recognition error at: ';'

Could anybody help me with this?

Best Regards,
Philipp 

Jim Idle

unread,
May 21, 2014, 4:06:49 AM5/21/14
to antlr-di...@googlegroups.com
On Wed, May 21, 2014 at 3:25 PM, Philipp Nies <philipp...@gmail.com> wrote:
Hello,

since a few days I'm experimenting with ANTLR and I receive even with an easy grammar like the one mentioned below many errors.

grammar test;

addition: '2' '+' '2';

 line 1:0 token recognition error at: 'g'
<snip> 
line 3:21 token recognition error at: ';'

Could anybody help me with this?

Nobody can help you with the question as you have written it.

Anltr v3? v4? Are you storing this in a file called test.g? test.g4? What command are you running against this grammar that gives this output? Running in the IDE? Command line? Si the character encoding for the file utf-8? Did you provide some other lexer rules?

Provide more information and someone will help you.

Jim

Philipp Nies

unread,
May 21, 2014, 5:06:04 AM5/21/14
to antlr-di...@googlegroups.com
Hi,

I'm using ANTLRv4 via command line with the following commands:

cd C:\Users\Philipp\Desktop\modellb_demo\example1
antlr4 test.g4
javac test*.java
grun test addition -gui test.g4

antlr4 and grun are batch-files which contain the commands mentioned in the tutorial here. Furthermore the test.g4 file has ANSI-Encoding and I use JDK 1.8.0_05 for compilation.

Best Regards,
Philipp


Alia Ibrahim

unread,
May 21, 2014, 5:39:50 AM5/21/14
to antlr-di...@googlegroups.com
you need to remove test.g4 from your grun command
just use

grun test addition -gui

you then enter 2 + 2

Philipp Nies

unread,
May 21, 2014, 6:05:12 AM5/21/14
to antlr-di...@googlegroups.com
Hi,

if I send "grun test addition -gui" without "test.g4" it doesn't return to command prompt and just nothing happens even if I enter 2 + 2... :(

Best Regards,
Philipp

Jim Idle

unread,
May 21, 2014, 6:14:01 AM5/21/14
to antlr-di...@googlegroups.com
You have not catered for ignoring white space and you don't have an EOF to force the parser to consume past errors. You also don't have any action code.

Keep reading through the book but also check that your CLASSPATH variable is unset and so on.

Alia is correct, you don't use the .g4 file here.

Jim


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

Alia Ibrahim

unread,
May 21, 2014, 6:27:28 AM5/21/14
to antlr-di...@googlegroups.com
oh, you are right Jim, another thing you mentioned  i forgot

i have tried it and it is working but you also need to ignore white space in your grammar

Alia

Alia Ibrahim

unread,
May 21, 2014, 6:44:57 AM5/21/14
to antlr-di...@googlegroups.com


Hi,

if I send "grun test addition -gui" without "test.g4" it doesn't return to command prompt and just nothing happens even if I enter 2 + 2... :(

Best Regards,
Philipp

--


Philip after entering 2+2 you need to end the file and that is ctrl +z in windowns (^z)
it will work after

Alia

Philipp Nies

unread,
May 21, 2014, 6:58:54 AM5/21/14
to antlr-di...@googlegroups.com
Hi,

thank you very much! It works now perfectly! :)

Beste Regards,
Philipp
Reply all
Reply to author
Forward
0 new messages