Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8540495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:36:37+00:00 2026-06-11T11:36:37+00:00

I’m having trouble following the steps to make my bison/flex parser reentrant with a

  • 0

I’m having trouble following the steps to make my bison/flex parser reentrant with a minimum amount of fuss.

The problem appears to be in the lexer. Since everything parser is re-entrant, I can no longer assign yylval directly. Instead, according to the Flex manual, I have to call this function:

void yyset_lval ( YYSTYPE * yylvalp , yyscan_t scanner );

But the problem is, YYSTYPE is an integral type. It isn’t a dynamically allocated value, and it isn’t an lvalue at all, so I can’t pass a pointer to it! Am I missing something, and if not, how am I supposed to set yylvalue? I’ve never had this problem with a non-reentrant parser!

Update:
Ok, I think I may have gotten past the integral type issue. Now the parser appears to crash because no input is set up, and I am not finding any documentation on how to tell the lexer where to read input from.

Flex file:

%{
#define YYSTYPE Token // Token is a typedef to an integral type
// following two lines added per suggestion from Chris Dodd
#define YYPARSE_PARAM yyscan_t scanner
#define YYLEX_PARAM scanner

%}
%option reentrant
%option bison-bridge

// ...

{D}+{IS}?               {
    *yylval = Tokenint(strtol(yytext,0,10));
     return(CONSTANT); 
}

Bison file:

%{
#define YYSTYPE Token
%define pure-parser
%lex-param {void * scanner}
%parse-param {void * scanner}
%token CONSTANT
// ...

Getting a crash at this line in the parser:

*yy_cp = yyg->yy_hold_char;

I suspect I may not be initializing everything correctly for the parse. The manuals are very confusing on this subject, often referencing types or variable without explaining where they come from or why they are used. I am invoking the parse this way:

void * scanner;
yylex_init(&scanner);
yyparse(scanner); // Note: was &scanner, this is wrong and will crash!

From reading through the souce code, yylex_init is allocating a struct yyguts_t and zeroing it out. When I reach the crash, yy_cp is a null pointer, in fact the entire struct yyguts_t is still zero-ed out! So I suspect I am not initializing something properly, and that is resulting in it not knowing where to get input from.

Final edit:
I’m going to mark this question as closed as my original question was answered, and re-open the new problem as a new question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:36:38+00:00Added an answer on June 11, 2026 at 11:36 am

    Normally to make a reentrant parser/scanner, you’ll use %option bison-bridge in your .l file and %define api.pure in your .y file. This makes yylval an argument to yylex instead of a global variable. In addition, you need have:

    %{
    #define YYPARSE_PARAM yyscan_t scanner
    #define YYLEX_PARAM scanner
    %}
    

    in the top of your .y file to pass the extra scanner parameter through your parser to your lexer.

    Now if YYSTYPE is int (you have no %union or declaration of YYSTYPE in your .y file), then you’d set the token value in your .l by just saying *yylval = whatever;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I've tracked down a weird MySQL problem to the two different ways I was
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.