On Aug 2, 2008, at 8:23 AM, george smith wrote:

Hello,
I am building a compiler where i need a parser for the front end and another
one for the back end. So i will need two parsers in the same program
but there will be a conflict between the function names as with the global variables. Is there any way to change the names to resolve any conficts?
Thanks in advance
George.

This may not be the best way to do things (maybe somebody can comment as to why), but you can write the .y file to accommodate both parsers. That way you don't have to worry about name conflicts. For example in your .y file you can do something like

...
int lexState;
...
%token FRONTSTART BACKSTART
...
parser: FRONTSTART frontparser
    |      BACKSTART backparser
    |      error
    ;

...
lexState = FRONTSTART
yyparse();
...
lexState = BACKSTART
yyparse();
...

Assuming you use flex, you can start your .l file with something like

...
extern int lexState;
...
%x FRONTSTATE BACKSTATE
...
if (YY_START != lexState) {
 if (lexState == FRONTSTART)
  BEGIN(FRONTSTATE);
 else if (lexState == BACKSTART)
  BEGIN(BACKSTATE)
 else
  yyterminate();
 return(lexState);
}
...

I did something like this to get three parsers into one .y file. My parsers are small and everything works as it should. However, as I said above, I don't know if this is the best way to do things, but this implementation makes sense to me.

Aaron


_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to