help-bison
[Top][All Lists]
Advanced

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

RE: About recursive calls to yyparse


From: Jesus M. Diaz Hernandez
Subject: RE: About recursive calls to yyparse
Date: Mon, 17 Dec 2001 15:43:15 -0500 (EST)

On Sun, 16 Dec 2001, Matt Carter wrote:

Ok, that works fine, now i'm running into another problem, but that is
flex topic ;)

thanks  
> I ran into the exact same problem.  I solved it by declaring YYSTYPE
> ("typedef union {...} YYSTYPE;") in a separate header file, then #including
> that file at the top of the grammar file and wherever else I needed it.  If
> you do this, you must remove the %union directive in the grammar file.
> 
> Hope this helps.
> 
> -Matt
> 
> -----Original Message-----
> From: Jesus M. Diaz Hernandez [mailto:address@hidden
> Sent: Friday, December 14, 2001 3:54 PM
> To: address@hidden
> Subject: About recursive calls to yyparse
> 
> 
> 
> 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
> 
> 
> 
> 
> _______________________________________________
> Help-bison mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/help-bison
> 

-- 
 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]