I run the following commands to execute a flex program
flex myname.lex
gcc lex.yy.c -lfl
./a.out
But then the terminal doesnt display any output. Nor it returns to the main prompt.The program doesnt have any errors.
Thanks in advance..
4
Contributors
4
Replies
1 Day
Discussion Span
9 Months Ago
Last Updated
5
Views
Related Article:How to Install GU in Linux Ubuntu
is a Linux and Unix discussion thread by littlephild that has 1 reply and was last updated 8 months ago.
/*
*
* myname.lex : A sample Flex program
* that does token replacement.
*/
%%
%NAME { printf("%s",getenv("LOGNAME")); }
%HOST { printf("%s",getenv("HOST")); }
%HOSTTYPE { printf("%s",getenv("HOSTTYPE"));}
%HOME { printf("%s",getenv("HOME")); }
%%
/*myname.txt*/
Hello, my name name is %NAME. Actually
"%NAME" isn't my real name, it is the
alias I use when I'm on %HOST, which
is the %HOSTTYPE I use. My HOME
directory is %HOME.
Then I used following commands :
flex myname.lex
gcc lex.yy.c -lfl
./a.out myname.txt
The executable created by lex does not take any command line arguments and if you give it any, it will silently ignore them. It reads its input from stdin and writes its output to stdout. So as L7Sqr said, it doesn't do anything because it's waiting for you to enter some input.
If you want to use your lexer on your myname.txt, you should pipe the contents of the file into your lexer using input redirection, i.e. ./a.out < myname.txt.