Reputation: 301
In this lex part of a lex-yacc program what is the purpose of adding the lines
. return yytext[0];
\n return yytext[0];
This the lex part
%{
#include "y.tab.h"
%}
%%
a return A;
b return B;
. return yytext[0];
\n return yytext[0];
%%
What does it return when it encounters \n ?
Upvotes: 3
Views: 4042
Reputation: 96
Not sure why Ajay2707 posted a comment and not an answer, because he is right. According to http://dinosaur.compilertools.net/flex/manpage.html yytext is a string containing the token matched by flex. Taking [0] takes the first character. So
This is because the pattern '.' does not match \n
To put it short this lexer changes a and b to upper caps, and nothing else.
Upvotes: 2