RE: Very basic question about Flex

"Jannick" <[email protected]>
Newsgroups gmane.comp.parsers.bison.general
Message-ID <[email protected]>
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
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.