I am new to flex and bison. I am trying to write a simple grammar accepting the string :a word in lowercase followed by a word in upper case. below are my files-
file.l
%{
#include<stdio.h>
#include<string.h>
#include "y.tab.h"
int yywrap(void)
{
printf("parsing is done*\n");
//yylex();
//return 0;
}
%}
%%
[a-z]* { printf("found lower\n");
yylval=yytext;
return LOWER;
}
[A-Z]* { printf("found upper\n");
yylval=yytext;
return UPPER;
}
[ \n] ;
. ;
%%
void main()
{
yyin = fopen("file.txt", "r");
yylex();//this function will start the rules section.... it starts the parsing.....
fclose(yyin);
}//main ends
file.y
%{
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define YYSTYPE char *
int yylex(void);
void yyerror(const char *str)
{
fprintf(stderr,"error: %s\n",str);
}
%}
%token LOWER UPPER
%%
start :
|
start LOWER UPPER
{
printf("%s--%s\n",$2,$3);
}
%%
contents of file.txt is:
token TOKEN
this is how i compile and run:
flex file.l
yacc -d file.y
gcc lex.yy.c y.tab.c -o file
./file
The program gives warning warning: assignment makes integer from pointer without a cast [-Wint-conversion] yylval=yytext;
When I run the program (ignoring warning), the output is "found lower" i.e the program stops reading tokens after return LOWER. Can anyone help and tell me why is this running like this?Also why is the warning generated even though i specified #define YYSTYPE char * in file.y