help-bison
[Top][All Lists]
Advanced

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

About recursive calls to yyparse


From: Jesus M. Diaz Hernandez
Subject: About recursive calls to yyparse
Date: Fri, 14 Dec 2001 15:54:27 -0500 (EST)

Hi, i'm working on a compiler for a OO languaje, and i have one class
specification per file. I want, if i found a type not defined yet, search
for this class on the system, parse the missed class and continue the
initial parse process. I'm using a class Parser that encapsulates the
yyparse function,

class Parser {
  std::istream* isp;
  std::ostream* osp;
  FlexLexer* lex;

public:
  Parser (std::istream* is = 0, std::ostream* os = 0);
  ~Parser();
  friend std::istream& operator>>(std::istream&,Parser&);
};

std::istream& operator>>(std::istream& is,Parser& parser)
{
        parser.isp = &is;
        parser.lex->yyrestart(&is);
        lexer = parser.lex;

        if (yyparse() != 0)
                is.setstate(std::ios::failbit);
        else
                is.clear(is.rdstate() & ~(std::ios::failbit | 
std::ios::badbit));
        
        return is;
}

(Here lexer is a pointer to the  lexical analyzer object)

So i'm talking of doing somethink like this:


typedef  : IDENTIFIER
        {
          if (not_found_in_class_register($1)) {

                ifstream aux(find_file_on_path($1));

                Parser p;

                aux >> p;
                ... 
          }
        }

So i look on the info and i realize that i need a reentrant parse, so
yyvalue become local to yyparse. The point is that when i define on my .y
file

%{

   yylex (YYSTYPE *lvalp) { return lexer->yylex(lvalp); };

%}

i get an error message that there is no defined type YYSTYPE

and if i put the yylex function at the end of the .y file i get the error
that yylex if used before its definition.

How can i do this?

Thanks in advance 

 -- 
 Jesus Miguel Diaz Hdez
 __________________________________

 Grupo de Redes
 Facultad de Matematica y Cibernetica
 Universidad de la Habana, Cuba

e-mail:
   address@hidden






reply via email to

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