|
From: | address@hidden |
Subject: | Re: Very basic question about Flex |
Date: | Fri, 22 Feb 2019 17:02:57 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 |
Now i've changed my rules to include whitespace and then the [a-zA-Z]+ rule. The code is now: %{ /** * First example program for flex * */ #include <stdio.h> #include <stdlib.h> %} %% is | am | are | where | was | be | being | been | do | does | did | should | can | could | has | have | had | go { printf("%s is a verb\n", yytext); } [ ]+[a-zA-Z]+ { printf("%s is not a verb", yytext); } .|\n { ECHO; /* normal default anyway */ } %% int main(int argc, char **argv) { yylex(); } gut when i try to compile: $flex test1.l $gcc lex.yy.c -o test -Wall i get: lex.yy.c:1192:16: warning: ‘input’ defined but not used [-Wunused-function] static int input (void) ^~~~~lex.yy.c:1149:17: warning: ‘yyunput’ defined but not used [-Wunused-function]
static void yyunput (int c, char * yy_bp ) ^~~~~~~ /tmp/ccAD7IfT.o: In function `yylex': lex.yy.c:(.text+0x4e6): undefined reference to `yywrap' /tmp/ccAD7IfT.o: In function `input': lex.yy.c:(.text+0x10f3): undefined reference to `yywrap' collect2: error: ld returned 1 exit status What includes do i need and how to get the warning away ? best regards! On 22.02.19 16:20, Jannick wrote:
On Fri, 22 Feb 2019 15:00:51 +0100, address@hidden wrote: If you replace[a-zA-Z]+ { printf("%s is not a verb", yytext); }by [a-zA-Z]+ printf("'%s' is not a verb\n", yytext); you will see that the scanner does exactly what it is expected to do, since the line.|\n { ECHO; /* normal default anyway */ }makes it print any character (inkl. '\n') not in [a-zA-Z] to stdout.Now my question is when i enter one of the verbs it's working normaly like expected, but when i enter for example 234someword i also get the messsage %s is not a verb but i've no rule saying thatWell, things are printed in different bits to stdout as you might think in the first place: The scanner prints each of the leading integers applying the last rule to each of them, then it pushes 'someword' through the [a-zA-Z]+ rule. If you apply the suggested change above, you'll see the difference. And if in addition you replace 'ECHO' (which is a C macro) by a printf statement with some enclosing tags around the character and a trailing newline, it might be easier to guess what is happening behind the scenes. BTW: Not sure if this is the right place to address pure flex issues, but I leave it with others to judge on this. HTH. J. _______________________________________________ address@hidden https://lists.gnu.org/mailman/listinfo/help-bison
[Prev in Thread] | Current Thread | [Next in Thread] |