help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: error


From: Hans Aberg
Subject: Re: error
Date: Mon, 16 Sep 2002 12:17:37 +0200

At 22:37 -0700 2002/09/15, Pratima Nallapaneni wrote:
> I resolved all the earlier errors . But I am still
>having once error. That is I am declaring
>
>extern FILE *yyin;
>
>after the include statements outside the main
>somewhere.
>
>When I use it in the main in the following way. It is
>giving me errors.
>if( ..)
> yyin = fopen( argv[0], "r" );
>else
> yyin = stdin;
>Its giving me error saying :
>undefined symbol: yyin
>
>How do I resolve this. I am using 1.24 version of
>Bison and I am running the program in UNIX.
>Please help me

It looks like a Flex problem to me. Flex problems should be directed to
   Help-flex mailing list
   address@hidden
   http://mail.gnu.org/mailman/listinfo/help-flex

As for yyin, etc., these are usually just macros, and not global names.
Therefore use the interface that the Bison & Flex manuals suggest. Then put
some wrap in the .y or .l file which can be used elsewhere. Under C++, I
used in my .y file:

CLPParser::CLPParser(std::istream* ip, std::ostream* op)
 : isp(ip), osp(op) { lex = new yyFlexLexer(isp, osp); }

CLPParser::~CLPParser() { delete lex; }

std::istream& CLPParser::operator>>(clp::Database& d) {
        db = &d;
        lex->yyrestart(isp);
        CLPLexer = lex;
        if (yyparse() != 0)
          isp->setstate(std::ios::failbit);
        else
          isp->clear(isp->rdstate() & ~(std::ios::failbit | std::ios::badbit));
        return *isp;
}

That is, I compile with
  bison --name-prefix=CLPParser ...
  fles -PCLPParser
and the wrap a CLPParser::operator>>() around that.

Then I can read a file by using:

    Database db;

    std::ifstream is(stdlib.c_str()); // Open file.
    if (!is) {
      std::cerr << "Library " << stdlib << " not found." << std::endl;
//      return EXIT_FAILURE;
    } else {

    std::cout << "Reading " << stdlib << ":" << std::endl;
    is >> db; // Parse and record in the database.
    if (!is) {
      std::cerr << "Could not read library " << stdlib << "." << std::endl;
      return EXIT_FAILURE;
    }
    std::cout << "Done!" << std::endl;
    }

That is, operator>>() knows how to consult the parser and record the parsed
objects in the database.

My guess is that the above is a more advanced interface; you might want to
start with something simpler.

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]