开发者

What to do with the output of lex?

I have absolutely no background in compilers and started off on a "teach myself" journey. I am learning about lex using this tutorial and typed something like this into a file called first.l

%%
    /* match everything except newline */
.   ECHO;
    /* match newline */
\n ECHO;

%%

int yywrap(void) {
    return 1开发者_开发问答;
}

int main(void) {
    yylex();
    return 0;
}

Now I understand that lex is supposed to generate a tokenizer that will just echo everything it gets using the above first.l file. I went ahead and ran

lex first.l

It created a file called lex.yy.c. The tutorial then gives a few more examples and jumps to yacc. Can someone tell me what can be done with lex.yy.c file that is generated by lex? My thought was that I now have a tokenizer but how do I compile this file to a binary now? Using gcc?


Yes, using GCC. You probably want to do something like this:

gcc -c file1.c
gcc -c file2.c
gcc -o result file1.o file2.o

The -c flag to GCC tells it not to link, but stop after generating an object file. Once you've compiled all the files, you can link it together by passing them all to gcc.

So in your case, you would just go ahead and compile the output file generated by lex to get the binary:

gcc -o output lex.yy.c
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜