William Jockusch
William Jockusch

Reputation: 27295

ANTLR "[Token name] is already defined" errors when building in visual studio 2012

I have a very simple ANTLR parser building in Visual Studio 2012. It works. But when it builds the grammar file, it emits a warning for every token, saying that the token is already defined. What could be causing this?

Here is the grammar file SimpleCalc.g4:

 grammar SimpleCalc;

 options {
 language=CSharp2;
 }

 tokens {
     PLUS,
     MINUS, 
     TIMES,
     DIV
     }

@members {

}

expr    : term ( (PLUS|MINUS) term )* ;
term    : factor ( ( TIMES|DIV ) factor )* ;
factor  : NUMBER ;
DIV : '/';
PLUS : '+';
TIMES: '*';
MINUS: '-';

NUMBER : (DIGIT)+   {System.Console.WriteLine("Found number");  };
WHITESPACE: ( '\t' | ' ' | '\r' | '\n' | '\u000C' )+   -> skip ;
fragment DIGIT  : '0'..'9';

And here are the warnings:

[path]\SimpleCalc.g4(8,3): warning AC0108: token name 'PLUS' is already defined
[path]\SimpleCalc.g4(9,3): warning AC0108: token name 'MINUS' is already defined
[path]\SimpleCalc.g4(10,3): warning AC0108: token name 'TIMES' is already defined
[path]\SimpleCalc.g4(11,3): warning AC0108: token name 'DIV' is already defined 

Upvotes: 0

Views: 91

Answers (1)

Terence Parr
Terence Parr

Reputation: 5962

I would get rid of the unnecessary tokens {...} block.

Upvotes: 2

Related Questions