>> On Tue, 15 Apr 2003 12:44:49 -0400, >> Joey Hess <[EMAIL PROTECTED]> said:
> Manoj Srivastava wrote: >> Flex sets up a number of things that are available in the rules >> section, and now cleans it all up before polluting the user >> namespace. Now, actions can be any C statement, but using >> functions that in turn use flex macros is going to be a problem >> since declaring the function is going to be problematic. >> >> Some of these changes were driven by the need to make flex >> scanners reentrant, others by hte requirements for having multiple >> scanners, perhaps with different options, in the same program. > It seems to promote bad coding style to require that reasonable > little functions like this: > eos() { > if (yytext[yyleng-1] == '.') > dintI(); > else > yyunput(yytext[yyleng-1], yytext); >> > Must be inlined into the rules block or defined as macros or > something, instead of just being defined as regular functions. Not quite. ---------------------------------------------------------------------- In the rules section, any indented or %{ %} enclosed text appearing before the first rule may be used to declare variables which are local to the scanning routine and (after the declarations) code which is to be executed whenever the scanning routine is entered. Other indented or %{ %} text in the rule section is still copied to the output, but its meaning is not well-defined and it may well cause compile-time errors (this feature is present for POSIX compliance. See *Note Lex and Posix::, for other such features). Any _indented_ text or text enclosed in `%{' and `%}' is copied verbatim to the output (with the %{ and %} symbols removed). The %{ and %} symbols must appear unindented on lines by themselves. ---------------------------------------------------------------------- I'll attach a file at the end that uses functions once again. Just the placement of these function definitions has changed. >> > Oh and why do I need an expliciy main() and yyweap() function >> > now? This code always worked before with flex generating stub >> > functions automatically. The real code is in the filters >> > package, in cockney.l, jive.l, and others. >> >> With multiple scanners now possible in the same program, flex >> would not know where to put main, obviously, it shoulkd not >> generate stubs in all the scanners generated. >> >> What is yyweap? > Typo for 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. manoj
%{ /* COMMENT: code block */ %} %option noyywrap /* COMMENT: Definitions Section */ BW [ \t\n] SP [ \t]+ EW [ \t.,;!\?$] %% /* COMMENT: Rules Section */ %{ /* COMMENT: Define function */ void foo () { unput(yytext[yyleng-1]); } %} foo /* COMMENT: after regex */ foo(); /* COMMENT: after code block */ /* COMMENT: Rules Section (indented) */ %% /* User COMMENT: Code Section */ int main(void) { yylex(); }
-- If you live to the age of a hundred you have it made because very few people die past the age of a hundred. George Burns Manoj Srivastava <[EMAIL PROTECTED]> <http://www.debian.org/%7Esrivasta/> 1024R/C7261095 print CB D9 F4 12 68 07 E4 05 CC 2D 27 12 1D F5 E8 6E 1024D/BF24424C print 4966 F272 D093 B493 410B 924B 21BA DABB BF24 424C