Flex reads data from variable yyin
, which is of the file or file type.
By default, this variable is associated with input STDIN
.
You can associate this variable to another file or file (e.g., in a parameter) via the command yyin = fopen("nome_do_arquivo.zzz", "r");
.
Here is an example from the Flex manual:
main( argc, argv )
{
int argc;
char **argv;
if ( argc > 0 )
yyin = fopen( argv[0], "r" );
else
yyin = stdin;
yylex();
}
If the function is in a DLL
, you can send the file name as a function parameter. Example:
__attribute__ ((dllexport)) int funcao_da_dll(const char *nome_arquivo)
{
yyin = fopen(nome_arquivo, "r" );
yylex();
}
For more references (in the item THE GENERATED SCANNER
):
FLEX
Yes, my problem is that this later is to integrate into a C# program as a DLL, so going through argument does not suit me. (Or serve and I’m not seeing how?)
– J. Pinto
I’m sorry @Rodrigoguiotti, this might help, but I need to know: how could I later say that inputfile was the new input for lex?
– J. Pinto
I don’t know if I understand your problem so... let’s see. Is the program in C and C# running? If they are, you will need to decide how the communication between the two processes will be. May be by file or local network interface. Depending on the operating system, you may have a better way.
– Rodrigo Guiotti
The C# program is working perfectly. Then I did a C routine that also works well. Now what I wanted was to add to the program in c# a dll to access the functions in c (but this is not the purpose of this question) E then send the string as parameter to the function in C and then run the lexical check. (I could tell?)
– J. Pinto
In this case, it seems that the program in C# will call your program in C. When C# decides the string, it can make a system call, like: System.Diagnostics.Process.Start(@"C: Windows test.exe inputfile"); No?
– Rodrigo Guiotti
I would prefer not to do so. There is no way to change the lex file or my c routine to read directly from a string? (and not from a file)
– J. Pinto
For both programs to use the same string, only using shared memory.
– Rodrigo Guiotti
It is possible to convert the C code to dll if it is managed. Use dllexport to expose the functions you want to access in C#. If the code is simple, it might be better to copy and paste in C# and fix what is not supported.
– Rodrigo Guiotti