Reputation: 336
After days of fagging I am still unable to find how can I declare my buffer. how to pass tkinter text to flex
What is the correct way to redirect flex buffer to my buffer? The steps I want to do: 1 - No conditions, no return to original buffer, just permanently redirect buffer from a graphic frontend by calling a function. 2 - Copy text from graphic frontend to my buffer (or even better to direct fely buffer to the frontend buffer) 3 - call yyparse 4 - repeat steps 2 and 3
Perhaps it is enough to declare a simple public function like this:
void setmybuffer(char *ptr)
{
yy_scan_string (char *ptr);
.... // my other stuff to set
}
Afterward I suppose I call it before any flex operation. But when I try to put this declaration into any part of my *.l file I get error
lex.yy.c: In function ‘setmybuffer’:
lex.yy.c:2206:18: error: conflicting types for ‘yy_scan_string’
YY_BUFFER_STATE yy_scan_string (char *ptr);
What's wrong and what's the way?
Upvotes: 1
Views: 294
Reputation: 241881
yyscan_string(char *ptr);
is a declaration, so the compiler complains that the function is already declared and with a different return type.
You wanted to call the function:
yyscan_string(ptr);
So you might do something like this:
// This defines the function setmybuffer, which has no return value ("void")
// and a single parameter which is a pointer to a character string ("char *")
void setmybuffer(char *ptr)
{
// This **calls** the function yy_scan_string, passing it the same pointer
// to a character string.
yy_scan_string (ptr);
.... // my other stuff to set
}
Note that you're required to free the YY_BUFFER_STATE
when you're finished with it. Usually you can simply call:
yy_delete_buffer(YY_CURRENT_BUFFER);
when you are finished with the input (eg. in your <<EOF>>
rule). For more complicated use cases, you might need to save the value returned by yyscan_string
.
Upvotes: 1