[Flex-help] Possibly outdated examples from manual
flex is a tool for generating scanners
Brought to you by:
wlestes
From: André W. V. <awv...@gm...> - 2016-09-11 19:58:49
|
Hello, I'm new to flex. I tried running examples from this page http://flex.sourceforge.net/manual/Simple-Examples.html#Simple-Examples on flex 2.6.0 (which came installed on Linux Mint 18). This example int num_lines = 0, num_chars = 0; %% \n ++num_lines; ++num_chars; . ++num_chars; %% int main() { yylex(); printf( "# of lines = %d, # of chars = %d\n", num_lines, num_chars ); } first produced a premature end-of-file as a result. After removing leading tabs, it produced a C source file with the following errors when compiled using gcc: <stdin>: In function ‘yylex’: <stdin>:4:3: error: ‘num_lines’ undeclared (first use in this function) <stdin>:4:3: note: each undeclared identifier is reported only once for each function it appears in <stdin>:4:16: error: ‘num_chars’ undeclared (first use in this function) <stdin>: In function ‘main’: <stdin>:14:9: error: ‘num_lines’ undeclared (first use in this function) <stdin>:14:20: error: ‘num_chars’ undeclared (first use in this function) I searched for a solution and found out that the first section of the file should be put between %{ and %}. The manual might need to be updated to conform with current versions of flex. Is that the case? Cheers, André |