A book that I am reading [1] says something that I need help understanding.
The book first describes the input(), output(), and unput() functions. Then it says this:
The use of output() allows Lex to be used as a tool for stand-alone data "filters" for transforming a stream of data.
Below is a lexer I created. It is a stand-alone data filter for transforming a stream of data (it finds all occurrences of a word and outputs the word and its line number). It does not use output(), it uses fprintf. How would my lexer be different if it used output()? Is it recommended to use output()? Please help me to understand the significance of what the book says.
%option noyywrap
%option always-interactive
%option yylineno
%{
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define DESIRED_STRING "FORMAT"
%}
%%
[^\n]+ {
char *ret;
ret = strstr(yytext, DESIRED_STRING);
if (ret) {
fprintf(stdout, "%d: %s\n", yylineno, yytext);
}
}
\n { }
%%
int main()
{yylex();}
[1] Crafting a Compiler with C, page 69.