Search code examples
clex

Compiling a Lex program on OS X


Is anyone able to better inform me on successfully compiling a Lex source file on OS X in terminal. I have written in HelloWorld.l the following:

%%

"hello world"    printf("GOODBYE\n");
.                ;

%%

Within the console I executed lex HelloWorld.l followed by gcc lex.yy.c -ll and ./a.out receiving a blank state within my window and no result.

I am basing my knowledge on this topic from the source [1] and similar Stack question [2].


Solution

  • flex, will by default, read from standard input. You need to actually provide it some input. You can do echo "hello world" | ./a.out and you should see your result.