views:

56

answers:

1

I want my flex/yacc program to do the same thing as what it already does, but I want to modify it a little. If I were to put a main() in my .l file, and have it do the same thing as if I didn't add a main(), then what would the code look like?

+2  A: 

You could generate you code as per normal, then copy your "normal main".

But as the standard parser expect input from stdin, all you should need to-do in main() is call yyparse()

according to 'lex & yacc' (page 211) the standard main is:

main(ac, av)
{
    yyparse();
    return 0;
}

there is a more complete example on page 96 that sets up the input and output via this type of code:

extern FILE *yyin, *yyout;

yyin = fopen(infile,"r");
if( yyin == NULL ) /* handle error */

yyout = fopen(outfile,"w")
/* error handling agian */

yyparse();

/* post processing */

exit(0);
Simeon Pilgrim