[antlr-interest] Re: C++ input

Ric Klaren klaren at cs.utwente.nl
Thu Mar 21 01:42:23 PST 2002

On Thu, Mar 21, 2002 at 09:31:04AM -0000, kordeul wrote:
> I use version 2.7.1 of ANTLR and there's no main2.cpp in the
> cpp/calc example. Can you write the actual code?

As I said in the 2.7.2a1 distribution but anyway..

It's stripped from all the fluff (error handling, namespace stuff and some
other details)

int main( int argc, char*argv[] )
   // write the argv strings to a ostringstream...
   ostringstream expr;
   for( int i = 1; i < argc; i++ )
		if( i > 1 && i != (argc-1))
			expr << ' ';
       expr << argv[i];

	 istringstream input(expr.str());  // prepare istringstream with input
	 CalcLexer lexer(input);
	 CalcParser parser(lexer);

With a file:

ifstream input("somefile.txt");

And then use Lexer and parser as above.

> Also I forgot to mention: I use Borland C++ Builder 5 if this
> changes something.

Dunno if C++ builder has istringstream support if not you'd better search
the archives for the CharInputBuffer stuff.

    ---- Ric Klaren ----- klaren at cs.utwente.nl ----- +31 53 4893722  ----
Wit is cultured insolence. --- Aristotle


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

More information about the antlr-interest mailing list