1
votes

Theres a bit of C code something like:

int doCommand(char* command)
{
    // +2 on strlen is for the two extra '\0' characters
    // needed by flex when scanning strings.
    YY_BUFFER_STATE yybs = yy_scan_buffer(command, strlen(command)+2);
    yy_switch_to_buffer(yybs);
    yyparse();
    yy_delete_buffer(yybs);
}

It gets called in a loop something like (psuedocode):

read characters upto and including '\n' into a buffer;
add two '\0' characters;
call doCommand(buffer);
zero the buffer; // NOTE: same buffer will be used next loop.

What goes wrong is that after the first command has been processed successfully, any further commands entered do not get processed.

I have printed out yylineno (which gets increased when the flex scanner sees '\n') and it only increases once, after the first command.

I cant work out if it is something Im doing wrong with flex, or if it is yyparse that stops calling the scanner after the first go.

I would be most pleased if someone could point out exactly what is happening.

1

1 Answers

2
votes

Can you please try this with a debug? Check which tokens are read. Whether it switches in time, what is the input.

I don't use flex enhancements, because i need portability, so i implement this mechanism a bit differently - through YY_INPUT. Probably the produced tokens are different from what you expect, so i advise to debug the lex part first.