Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 74757
336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 3762
536
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.  
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic