Unable to compile output of lex

前端 未结 2 1487
执念已碎
执念已碎 2020-12-17 01:48

When I attempt to compile the output of this trivial lex program:

# lex.l
integer   printf(\"found keyword INT\");

using:

$         


        
相关标签:
2条回答
  • 2020-12-17 02:07

    As Eli's answer implies, that's not a trivial lex program. It's a trivial lex file, and thus a portion of a program, but it (like any lex file) needs to be combined with some C code to make a complete program. In particular, you still need a main function (which you write in C or C++ or something, in a separate file), and you will also need to write a yywrap function that provides the interface between the lex code and the rest of your C code.

    0 讨论(0)
  • 2020-12-17 02:11

    From the Flex manual:

    I get an error about undefined yywrap().

    You must supply a yywrap() function of your own, or link to libfl.a (which provides one), or use

    %option noyywrap
    

    in your source to say you don't want a yywrap() function.

    Also:

    When the scanner receives an end-of-file indication from YY_INPUT, it then checks the yywrap() function. If yywrap() returns false (zero), then it is assumed that the function has gone ahead and set up yyin to point to another input file, and scanning continues. If it returns true (non-zero), then the scanner terminates, returning 0 to its caller. Note that in either case, the start condi- tion remains unchanged; it does not revert to INITIAL.

    0 讨论(0)
提交回复
热议问题