Re: Very basic question about Flex

"[email protected]" <[email protected]>
Newsgroups gmane.comp.parsers.bison.general
Message-ID <[email protected]>
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, [email protected] 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 that
> Well, 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.
>
>
> _______________________________________________
> [email protected] https://lists.gnu.org/mailman/listinfo/help-bison
>
_______________________________________________
[email protected] https://lists.gnu.org/mailman/listinfo/help-bison
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.