tags:

views:

116

answers:

2

How to call a flex parser in c ?

+5  A: 

By calling yylex().

By default lex reads from stdin, if you want it to read from other stream, assign yyin, like

yyin = fopen("myfile", "r");
qrdl
+1  A: 

It's worth noting that yylex is not declared anywhere so you need to declare it:

int yylex ();

Traditionally it seems that the entire output of lex or flex would be incorporated in the C program via #include.

Recent versions of Flex include an option to create a header file, either on the command line via the

--header-file

option, or in the script

%option header-file

The header file contains stuff which can be used, for example, to ask Flex to read from memory rather than a file.

Kinopiko