delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/12/05/08:27:43

From: rafael AT alpha DOT coe DOT ufrj DOT br (Rafael Gustavo da Cunha Pereira Pinto)
Subject: Re: Multiple FLEX/BISONs in one program ?
To: tony AT nt DOT tuwien DOT ac DOT at
Date: Mon, 5 Dec 94 8:00:02 GMT-3:00
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu (djgpp Mailing List)

> 
> Hi,
  Hi! :)
> 
> I have used FLEX/BISON for scanners and parsers many times before, but now I
> should 
> parse 3 different files (with different grammars) in one program.
> Both BISON and FLEX allow to change their global variables using the -p (or
> -P) commandline
> option. Multiple use should therefore be possible.

   God! Is there an option to do this? I always did it by hand when using
lex & yacc (the simpler versions of Flex & Bison)!

> But...
> When using e.g. -paa I get an unresloved symbol "aaerror" (was yyerror
> before) while linking.
> yyerror seems to be in libbison.a
> Anyway, there might be more problems, I haven't figured out yet.

  Ok... let's go... Using an UNIX environment, you have two programs to do 
this: yacc and lex. To use them, the programmer must define some functions
to modify their behavior. They are:

  yyerror- Syntax error handler for yacc 
  yywrap - This function must return 1 if the end of all files was reached
           or 0 if a new file was opened in yyin.

  Yes, you can close yyin and yyout, the standard lex input and output files,
to another set while running. 
  Your problem seem to be simple. When you change the names of the functions
using the -p option, their default definitions are lost (there's only yy* in
libflex.a) and you must redefine them. 

> Has someone successfully applied multiple scanners/parsers in one program
> using FLEX/BISON ?
> I studied the docs, but didn't find any hint.
> 
> Any ideas welcome !
> 
> Tony
> 

   Here are some examples of possible functions:

int yywrap() {
  return 1;
}

int yyerror (char *s) {
  printf("%s",s);
  exit (-1);
}

  This means: If the yyin eof was reached, exit.
              If an error has occurred, print the error message and exit.

  You can change yywrap to verify if there is any other file to process, open
the input using yyin = fopen(...) and return 0 to continue process.
  You also can change yyerror to give the error message, pop the incorrect
tokens out of the stack (the parser uses a stack to store the state and current
symbol) and continue the parsing. This is hard to do, but gives a wonderful 
error handling!

   Hope this helps

      Regards,
         Rafael Pinto


----------------------------------------------------------------------------
Rafael Gustavo C. P. Pinto            | Phone: 55-21-598-2454
Software Engineer - CEPEL             | Fax:   55-21-260-1340
Electric Power Research Center        | 
P.O. Box 2754                         | E-Mail:rafael AT acsi DOT cepel DOT br
Rio de Janeiro, RJ 20.001 - Brasil    |        rafael AT fund DOT cepel DOT br
                                      |        rafael AT coe DOT ufrj DOT br
----------------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019