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 8673123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:22:34+00:00 2026-06-12T19:22:34+00:00

So, here’s the story. I’m trying to create a recursive descent parser that tokenizes

  • 0

So, here’s the story. I’m trying to create a recursive descent parser that tokenizes a string and then creates a tree of nodes out of those tokens.

All of the pointers for my major classes are working… if you’re worked with an RDP before then you know what I’m talking about with program -> statement -> assignStmt… etc. The idea being that the program node has a child that points to the statement node, etc.

Here’s the problem. When I get to the end of the treenode I’m pointing to the actual tokens that the tokenizer created from the string.

So, let’s say the string is:

 firstvar = 1;

In this case there are 4 tokens [{id} firstvar], [{assignment} =], [{number} 1], [{scolon}]

And I want my assignStmt node to point to the non-decorator portions of that statement.. namely, child1 of assignStmt would be [{id} firstvar] and child2 would be [{number} 1]…

HOWEVER. When I assign child1 to [{id} firstvar], and then move onward to the next tokens, the value of child1 changes as I move forward. So, if I change my global token to the next token ( in this case [{assignment} =] ) then child1 of the assignStmt changes with it.

Why is this? What can I do?! Thank you!

TOKEN* getNextToken(void); 
//only shown here to you know the return... it's working properly elsewhere

typedef struct node {
    TOKEN *data;

    struct node *child1, *child2, *child3, *child4, *parent;

} node;

TOKEN *token;
Symbol sym;
struct node *root;

void getsym() 
{
    token = getNextToken();
    sym = token->sym;
}

int main()
{
    getsym();
    //So, right now, from getsym() the global token has the value {identifier; firstvar} 

    struct node* tempNode;
    tempNode = (struct node*) calloc(1, sizeof(struct node));
    tempNode->child1 = tempNode->child2 = tempNode->child3 = tempNode->child4 =  NULL;
    tempNode->data = token;

    getsym();
    //BUT NOW from getsym() the global token has the value {assignment; =}, and 
    //subsequently the tempNode->data has changed from what it should be 
    //{identifier; firstvar} to what the global token's new value is: {assignment; =}

}
  • 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-12T19:22:36+00:00Added an answer on June 12, 2026 at 7:22 pm

    You are returning a pointer to a global variable, and that pointer will always be the same even if you modify the global variable.

    The solution is to either allocate a new object each time, or to not use pointers at all and return the structure directly and let the compiler handle copying of the structures internal values.

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

Sidebar

Related Questions

Here's what I'm trying to accomplish with this program: a recursive method that checks
Here is the problem that I am trying to solve. I have two folders
I'm trying to create an if statement in PHP that prevents a single post
Here is what I am trying to achieve in PHP: I have this string:
Here is the code in a function I'm trying to revise. This example works
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here is my SQL script CREATE TABLE tracks( track_id int NOT NULL AUTO_INCREMENT, account_id
Basically, what I'm trying to create is a page of div tags, each has
Here is my AsyncTask. Getting exception in the AsyncTask.. private class GetCategories extends AsyncTask<String,
Here is an example: I write html code inside of textarea, then I swap

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.