[antlr-interest] link error with antlr(Klaren edition)

lzy7886 lzy7886 at yahoo.com
Thu Sep 18 19:20:25 PDT 2003


Hi:

I have used antlr on java platform for some days,thanks for the smart 
work of those clever guys.It's wonderful.

However,I try to shift ANTLR to MSVC70 for the work which must be 
done on Windows,the problems arise.

I first built the antlr 2.7.2(Klaren 20030911) under MSVC70 to static 
lib.It completed successfully.But when I wrote a small program and 
try to build it,the problems came into being,it couldn't be linked 
correctly.

The compiler said some construct had already defined in some default 
lib.
such as:
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "class 
std::basic_ostream<char,struct std::char_traits<char> > & __cdecl 
std::operator<<(class std::basic_ostream<char,struct 
std::char_traits<char> > &,char const *)" (??6std@@YAAAV?
$basic_ostream at DU?$cha
r_traits at D@std@@@0 at AAV10@PBD at Z) already defined in antlrlibd.lib
(LLkParser.obj)
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall 
std::basic_string<char,struct std::char_traits<char>,class 
std::allocator<char> >::~basic_string<char,struct 
std::char_traits<char>,class std::allocator<char> >(void)" (??1?
$basic_strin
g at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@QAE at XZ) already 
defined in antlrlibd.lib(LLkParser.obj)
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: class 
std::basic_ostream<char,struct std::char_traits<char> > & __thiscall 
std::basic_ostream<char,struct std::char_traits<char> >::operator<<
(class std::basic_ostream<char,struct std::char_traits
<char> > & (__cdecl*)(class std::basic_ostream<char,struct 
std::char_traits<char> > &))" (??6?$basic_ostream at DU?
$char_traits at D@std@@@std@@QAEAAV01 at P6AAAV01@AAV01@@Z at Z) already 
defined in antlrlibd.lib(LLkParser.obj)
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "class 
std::basic_ostream<char,struct std::char_traits<char> > & __cdecl 
std::endl(class std::basic_ostream<char,struct std::char_traits<char> 
> &)" (?endl at std@@YAAAV?$basic_ostream at DU?$char_traits at D@std@@
@1 at AAV21@@Z) already defined in antlrlibd.lib(LLkParser.obj)

I cannot figure out the solution to it.
Can anybody help me out?
Thanks very much in advance.

                                         Yours, 
                                         Rockson

Following is the my .g file,quite simple.


header "pre_include_hpp" {
    // gets inserted before antlr generated includes in the header 
file
    #include <iostream>
    #include <string>
}

options {
	language="Cpp";
}
{
ANTLR_USING_NAMESPACE(std)
}
class StclParser extends Parser;
options {
	importVocab=Stcl;  // call the vocabulary "Stcl"
	//buildAST = true;	// uses CommonAST by default
	genHashLines=false;
}
stats
	:(stat)*
	  EOF
	;	
stat
	: wait_stat
	 |waitto_stat
	 |pause_stat
	 |send_stat
	 |check_stat
	 |call_stat
	;
wait_stat
	:wait:WAIT n:NUM_INT
	{cout<<wait->getText()<<" "<<n->getText()<<endl;}
	;
waitto_stat 
	:w:WAITTO t:TIME
	{std::cout<<w->getText()<<" "<<t->getText()<<endl;}
	;
pause_stat
	:p:PAUSE
	{std::cout<<p->getText()<<endl;}
	;
send_stat
	:s:SEND i:IDENT {std::cout<<s->getText()<<" "<<i->getText()
<<" ";}
	(c:COMMA n:NUM_INT{std::cout<<c->getText()<<" "<<n->getText
();})?
	{std::cout<<endl;}
	 
	;
check_stat
{string c,n;}
	:check:CHECK ident:IDENT c=check_op n=num str:STRING_LITERAL
	{std::cout<<check->getText()<<" "<<ident->getText()
<<" "<<c<<" "<<n<<" "<<str->getText()<<endl;}	
	;
check_op
returns[std::string op]
	: opE:EQUAL	{op=opE->getText();}
	 |opN:NOT_EQUAL {op=opN->getText();}
	 |opGE:GE	{op=opGE->getText();}
	 |opGT:GT	{op=opGT->getText();}
	 |opLE:LE	{op=opLE->getText();}
	 |opLT:LTHAN	{op=opLT->getText();}
	 ;	
call_stat
	:call:CALL ident:IDENT
	{std::cout<<call->getText()<<" "<<ident->getText()<<endl;}
	;
num
returns[std::string number]
{
std::string sign="";
}
	:
	 (p:PLUS{sign=p->getText();}|m:MINUS{sign=m->getText();})?
	 (
	   nI:NUM_INT	{number=sign+nI->getText();}
	  |nF:NUM_FLOAT	{number=sign+nF->getText()+sign;}
	  )	 	 
	;						
//--------------------------------------------------------------------
--------
// The Stcl scanner
//--------------------------------------------------------------------
--------
class StclLexer extends Lexer;

options {
	exportVocab=Stcl;  // call the vocabulary "Stcl"
	testLiterals=false;    // don't automatically test for 
literals
	k=2;                   // four characters of lookahead
	codeGenBitsetTestThreshold=5;
	//charVocabulary='\x00\x03'..'\xFF\xFE';//note:here exclude 
the \uFFFF(16bit -1:EOF)
	charVocabulary = '\3'..'\377';
	
}
tokens
{
CHECK	="CHECK"	;
SEND	="SEND"		;
WAIT	="WAIT"		;
WAITTO	="WAITTO"	;
PAUSE	="PAUSE"	;
CALL	="CALL"		;
NUM_FLOAT		;
TIME			;
DOT			;
}


// OPERATORS

LPAREN			:	'('		;
RPAREN			:	')'		;
COMMA			:	','		;
EQUAL			:	"=="		;
NOT_EQUAL		:	"!="		;
GE			:	">="		;
GT			:	">"		;
LE			:	"<="		;
LTHAN			:	'<'		;
PLUS			:	'+'		;
MINUS			:	'-'		;

	

// Whitespace -- ignored
WS	:	(	' '
		|	'\t'
		|	'\f'
		// handle newlines
		|	(	"\r\n"  // Evil DOS
			|	'\r'    // Macintosh
			|	'\n'    // Unix (the right way)
			)
			{ newline(); }
		)
		{ _ttype = ANTLR_USE_NAMESPACE(antlr)Token::SKIP; }
	;

// Single-line comments
SL_COMMENT
	:	"--"
		(~('\n'|'\r'))* ('\n'|'\r'('\n')?)
		{$setType(ANTLR_USE_NAMESPACE(antlr)Token::SKIP); 
newline();}
	;
// character literals
CHAR_LITERAL
	:	'\'' ( ESC | ~'\'' ) '\''
	;

// std::string literals
STRING_LITERAL
	:	'"' (ESC|~('"'|'\\'))* '"'
	;


// escape sequence -- note that this is protected; it can only be 
called
//   from another lexer rule -- it will not ever directly return a 
token to
//   the parser
// There are various ambiguities hushed in this rule.  The optional
// '0'...'9' digit matches should be matched here rather than letting
// them go back to STRING_LITERAL to be matched.  ANTLR does the
// right thing by matching immediately; hence, it's ok to shut off
// the FOLLOW ambig warnings.
protected
ESC
	:	'\\'
		(	'n'
		|	'r'
		|	't'
		|	'b'
		|	'f'
		|	'"'
		|	'\''
		|	'\\'
		|	('u')+ HEX_DIGIT HEX_DIGIT HEX_DIGIT 
HEX_DIGIT 
		|	('0'..'3')
			(
				options {
					warnWhenFollowAmbig = 
false;
				}
			:	('0'..'7')
				(	
					options {
					
	warnWhenFollowAmbig = false;
					}
				:	'0'..'7'
				)?
			)?
		|	('4'..'7')
			(
				options {
					warnWhenFollowAmbig = 
false;
				}
			:	('0'..'9')
			)?
		)
	;
protected
DIGIT
	:'0'..'9'
	;

// hexadecimal digit (again, note it's protected!)
protected
HEX_DIGIT
	:	('0'..'9'|'A'..'F'|'a'..'f')
	;

// an identifier.  Note that testLiterals is set to true!  This means
// that after we match the rule, we look in the literals table to see
// if it's a literal or really an identifer
IDENT
	options {testLiterals=true;}
	:	('a'..'z'|'A'..'Z'|'_'|'$') 
('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'$')*
	;


// a numeric literal
NUM_INT
	{bool isDecimal=false;}
	:
	  
	  '.' {_ttype = DOT;}
		(('0'..'9')+ (EXPONENT)? (FLOAT_SUFFIX)? { _ttype 
= NUM_FLOAT; })?	
	  |((DIGIT)+ 'd' DIGIT (DIGIT)? 'h')=>
			(DIGIT)+ 'd' DIGIT (DIGIT)? 'h' DIGIT 
(DIGIT)? 'm' DIGIT (DIGIT)? 's'
		{$setType(TIME);}	  	
	  |	(	'0' {isDecimal = true;} // special case 
for just '0'
			(	('x'|'X')
				(			
				// hex
					// the 'e'|'E' and 
float suffix stuff look
					// like hex digits, 
hence the (...)+ doesn't
					// know when to stop: 
ambig.  ANTLR resolves
					// it correctly by 
matching immediately.  It
					// is therefor ok to 
hush warning.
					options {
					
	warnWhenFollowAmbig=false;
					}
				:	HEX_DIGIT
				)+
			//|	('0'..'7')+		
				// NO octal
			)?
		|	('1'..'9') ('0'..'9')*  {isDecimal=true;}
		// non-zero decimal
		)
		(	('l'|'L')
		
		// only check to see if it's a float if looks like 
decimal so far
		|	{isDecimal}?
			(	'.' ('0'..'9')* (EXPONENT)? 
(FLOAT_SUFFIX)?
			|	EXPONENT (FLOAT_SUFFIX)?
			|	FLOAT_SUFFIX
			)
			{ _ttype = NUM_FLOAT; }
		)?	   	   		
	;


// a couple protected methods to assist in matching floating point 
numbers
protected
EXPONENT
	:	('e'|'E') ('+'|'-')? ('0'..'9')+
	;


protected
FLOAT_SUFFIX
	:	'f'|'F'|'d'|'D'
	;

	
	








 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list