• Post Reply Bookmark Topic Watch Topic
  • New Topic

flex bison, tokenizing stops after encountering a token while reading from a file  RSS feed

 
ravindra koranga
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

0
down vote
favorite
I am new to flex and bison. I am trying to write a simple grammar accepting the strings :a word in lowercase followed by a word in upper case. below are my files-

file.l



file.y


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 . Can anyone help and tell me why is this running like this?Also why is the warning generated even though i specified in file.y
 
ravindra koranga
Greenhorn
Posts: 27
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the solution to this problem. To anyone else facing same problem here is the solution.
for warning part add
#define YYSTYPE char * in the definition section of both file.l and file.y
For part 2)
The bison parser calls yylex() whenever it needs a token. So no need to run yylex(). just run yyparse();
so main function of file.l is
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done sorting it out
Note that flex and bison use very old‑fashioned programming idioms and appear to be written in C, so they need define directives, and flex returns a pointer to the token parsed. What sort of guide have you got to flex and bison? When I used them, so long ago that I have forgotten how to use them, I read Levine Brown and Mason's book.
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ravindra koranga wrote:I got the solution to this problem. To anyone else facing same problem  ...

Thanks for reporting back with your solution. 
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!