dcsimg
i need a simple main.cpp example
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   merom_klein
Posted On:   Monday, April 30, 2001 01:52 AM

Hi can you supply a main.cpp example as you did in the java version main.java? i tried to create my own main.cpp but it didn't compile well: #include #include "l.hpp" #include "p.hpp" void main () { using namespace std; basic_istream x(); L lexer(x); P parser(lexer); parser.startRule(); } i get the following compilation error: C:antlrantlr-2.7.1libcppsrcmain.cpp(13) : error C2664: '__thiscall L::L(class std::basic_istream > &)' : cannot convert parameter 1 from 'class std::basic_istream > (void)' to 'class std::basic_istream > &' Context does    More>>

Hi
can you supply a main.cpp example
as you did in the java version main.java?
i tried to create my own main.cpp
but it didn't compile well:

#include
#include "l.hpp"
#include "p.hpp"

void main ()
{

using namespace std;
basic_istream x();
L lexer(x);
P parser(lexer);
parser.startRule();
}

i get the following compilation error:

C:antlrantlr-2.7.1libcppsrcmain.cpp(13) : error C2664: '__thiscall L::L(class std::basic_istream > &)' : cannot convert parameter 1 from 'class std::basic_istream > (void)'
to 'class std::basic_istream > &'
Context does not allow for disambiguation of overloaded function

can you explain what is wrong with this
and how to fix it?
i need an answer urgently
i would appreciate it very much if you
answer this shortly
sincerely
merom klein

   <<Less

Re: i need a simple main.cpp example

Posted By:   Ric_Klaren  
Posted On:   Tuesday, May 1, 2001 02:15 AM

See in the examples/cpp directory
most of these parsers contain pretty
small main functions.

For the program you list it makes not much
sense creating a basic_istream like that.
In general you use std::cin or a fstream as
input to the lexer.

e.g. the one from tinyc:



#include // or iostream.h depending on age of compiler
#include "TinyCLexer.hpp"
#include "TinyCParser.hpp"

int main(int argc, char** argv)
{
try {
TinyCLexer lexer(std::cin); // read from stdin
TinyCParser parser(lexer);
parser.program();
} catch(std::exception& e) {
std::cerr << "exception: " << e.what() << std::endl;
}
return 0;
}


Or a small snippet for fstream usage


#include
#include
...
std::ifstream file;
file.open("infile.txt");
if( ! file.is_open() )
{
cerr << "Error opening file." << endl;
return -1;
}
TinyCLexer lexer(file);
...
etc.

About | Sitemap | Contact