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

  • Home
  • SEARCH
  • 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 7804343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:53:01+00:00 2026-06-02T01:53:01+00:00

Okay I have the following code in Bison .l file. By the way I

  • 0

Okay I have the following code in Bison .l file. By the way I am new to c.

exp: TK_SLIT    // TK_SLIT is a string literal token

      /* assigns the type to the nonterminal exp */
      $$ ->type = (char *) malloc (strlen ("string") + 1);  /* allocates space */
      strcpy ($$->type,"string");  /* puts value in there */ 
      printf ("%s\n",$$->type);

      printf ("The value of TK_SLIT is - %s\n",$1);

I have figured out that the “assigns type” block of code (4 lines including comment) OVERWRITES the value of TK_SLIT ($1) in memory. The value of TK_SLIT was grabbed from my scanner, FLEX.

I know that the block of code is causing the problem because if I comment out the “assigns type” block of code, then my TK_SLIT token value prints just fine. Otherwise it becomes garbled characters.

Is there something wrong with my malloc? Why is it overwriting my token value? Is this a bison issue where it’s not protecting my token values in memory?

Okay my union is as follows:

%union
{

    int intbison;
    char *charbison; // used for input
    char *boolbison;
    int voidbison;
    charlist *charlistbison;
    arraylist *arraylistbison;
    expnode *expnodebison;
}

Also here is my expnode from the header file:

   typedef struct expnode{
        char *type;
        typesymrec *typesymrecptr;
        varsymrec *varsymrecptr;
        char *stringval;
        int intval;
        int boolval;


}expnode;

And I made “exp” nonterminal the “expnodebison” type.

  • 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-02T01:53:03+00:00Added an answer on June 2, 2026 at 1:53 am

    Finally figured it out.

    The problem was that the $$ was an expnode struct type, and this needed to be malloc’d.

    Once I did this, my TK_SLIT $1 token was preserved. Below is the fix

    exp: TK_SLIT    // TK_SLIT is a string literal token
    
        $$ = (expnode *) malloc (sizeof (expnode));
        $$ ->type = (char *) malloc (strlen ("string") + 1);  /* allocates space */
        strcpy ($$->type,"string");  /* puts value in there */ 
        printf ("%s\n",$$->type);
    
        printf ("The value of TK_SLIT is - %s\n",$1);
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I have the following code: QFileSystemModel *model = new QFileSystemModel; model->setRootPath(QDir::currentPath()); model->setFilter(QDir::Files |
Okay so I have the following Code which appends a string to another in
Okay so i have a semi weridish problem with re.sub. Take the following code:
Okay I have updated my code quite a bit. I am getting a new
I have the following code: Dim dbHousing As New dcHousingDataContext Dim pullresidents = From
Okay, I have the following PHP code to extract an email address of the
I have the following script : <script type=text/javascriptsrc = //www.gmodules.com/ig/ifr?url=http://hosting.gmodules.com/ig/gadgets/file/100080069921643878012/facebook.xml&amp;up_useNewFB_p=1&amp;up_showPopUp2_p=true&amp;synd=open&amp;w=320&amp;h=500&amp;title=Facebook&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js></script> to use the igoogle
I have the following code: (define (get-data) (define port (open-input-file ../data/problem11.txt)) (define field 0)
I have an hpp file with following code: const float PixelsPerMeter = ConfigManager->Get<float>(koef, 100.0f);
Okay, so i have the following html added to a site using javascript/greasemonkey. (just

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.