[antlr-interest] How to feed in the lexer via char*

macromliu <macromliu at yahoo.com.cn> macromliu at yahoo.com.cn
Sat Dec 28 08:37:50 PST 2002


 I have to use the ANTLR in Visual C++ 6.0(SP5) with MFC support,

and I am using the ANTLR 2.7.0 (since i can not download the 2.7.1 
from the linkes in www.antlr.org, and can not compile the 2.7.1a 
sucessfully),

 but i meet a problem, the string to be lexered and pasered is 
resident in the file or buffer( char*) , so how can i feed the lexer?

 i have read the previous paper about how to feed the lexer via buf,
and also get the example --main2.cpp in calc (ANTLR 2.7.2a5 ), 
according to the example, i add two line at the beginning of cpp 
files.

#include <iostream>
#include <sstream>

and the lexer part's code like this...
CFile input("input.txt", CFile::modeRead);
char *buf = (char*)malloc(input.GetLength() + 1);
input.Read(buf, input.GetLength());
	
PassCondition passCond;
FILE *stream = freopen( "C:\\GMSSqlerror.txt", "w", stderr );

istringstream input(buf);

ANTLR_USING_NAMESPACE(std)
ANTLR_USING_NAMESPACE(antlr)
try {
   GMSPassLexer lexer(buf);
   GMSPassLexer lexer(input);
   lexer.setFilename("<arguments>");
   TokenBuffer buffer(lexer);
   GMSPassParser parser(buffer);
   parser.setFilename("<arguments>");
   parser.startParser(&passCond);
} catch(exception& e) {
   fprintf(stderr, "exception: ",  e.what());
}



and i got the following compile erro:

line(113) : error C2065: 'istringstream' : undeclared identifier
line(113) : error C2146: syntax error : missing ';' before  
identifier 'input'
line(113) : error C2064: term does not evaluate to a function
line(119) : error C2664: '__thiscall GMSPassLexer::GMSPassLexer(class 
std::basic_istream<char,struct std::char_traits<char> > &)' : cannot 
convert parameter 1 from 'class CFile' to 'class 
std::basic_istream<char,struct std::char_traits<char> > &' A 
reference that is not to 'const' cannot be bound to a non-lvalue 


so, what is wrong with it.....


how to solve this problem?
could anyone give me a tips??

:-)




 

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



More information about the antlr-interest mailing list