i’m trying to print out lexemes and tokens with using lexical analyzer “flex” and the problem is i can find lexemes and can just print tokens not lexemes. this is the simple code which i use as you can see below
%{
#include<stdio.h>
char RW[] = "RESERVE_WORD";
%}
int [i][n][t]
%%
int printf("%s --> %s\n", yylex(), RW);
.|\n { /* Ignore all other */}
%%
int main(int argc, char *argv[]) {
yyin = fopen(argv[1], "r");
yylex();
fclose(yyin);
return 0;
}
when i make a lexical analysis this yylex() function returns “null” and it says
example5.l:8:1: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat].
i will be glad if you can help me. and thanks anyway
ok i handled the problem. so the thing is we should use
yytextvariable which contains the last token of the lexical analyzer as a string. In Addition,yylex()function will return either the value of the next token or a number <= 0 indicating EOF.