[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Very basic question about Flex
From: |
Jannick |
Subject: |
RE: Very basic question about Flex |
Date: |
Fri, 22 Feb 2019 16:20:27 +0100 |
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 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.