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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:05:56+00:00 2026-05-11T05:05:56+00:00

My MIPS Assembly class required me to read in an expression of unknown size

  • 0

My MIPS Assembly class required me to read in an expression of unknown size into a Parse Tree. I’ve never had to deal with trees, so this is how I went around storing values:

Lets say the user entered the expression 1 + 3 – 4 (each operand could only be a digit 1-9)

My leftmost child node would be the starting point and contain 2 pieces of data

1. The operand 2. Pointer to the next node (operator) 

This is how I constructed the tree. I would point from operand to operator to next operand to next operator until there were no more values left to be read in.

My next task was to traverse the tree recursively and output the values in infix/prefix/postfix notation.

Infix traversal was no problem considering how I constructed my tree.

I’m stuck on the prefix. Firstly, I don’t fully understand it.

When I output our expression (1 + 3 – 4) in prefix should it come out – + 1 3 4? I’m having trouble following the online examples.

Also do you think my tree is constructed properly? I mean, I have no way to go to a previous node from the current node which means I always have to begin traversal from the leftmost child node which instinctively doesn’t sound right even though my TA said that was the way to go.

Thank you for any help.

  • 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. 2026-05-11T05:05:56+00:00Added an answer on May 11, 2026 at 5:05 am

    Your parse tree should look something like this:

             '-'          |      +---+---+      |       |     '+'     '4'      |  +---+---+  |       | '1'     '3' 

    Each node has two pointers. One to its left child and one to its right child. There is no need for pointers to parent nodes, when using recursive traversal.

    Here’s some pseudocode:

    Traversal for infix notation:

    void traverse(Node *node) {     if (node->leftChild != 0) {         traverse(node->leftChild);     }      print(node->value);      if (node->rightChild != 0) {         traverse(node->rightChild);     } } 

    Traversal for prefix notation:

    void traverse(Node *node) {     print(node->value);      if (node->leftChild != 0) {         traverse(node->leftChild);     }      if (node->rightChild != 0) {         traverse(node->rightChild);     } } 

    Traversal for postfix notation:

    void traverse(Node *node) {     if (node->leftChild != 0) {         traverse(node->leftChild);     }      if (node->rightChild != 0) {         traverse(node->rightChild);     }      print(node->value); } 

    You would call the traverse method with the root node of your tree.

    Your Node data structure would need three members:

    struct Node {     char value;     Node *leftChild;     Node *rightChild; } 

    The leaves of the tree would contain null pointers for leftChild and rightChild.

    Sometimes it helps to write this stuff in a higher level language (whatever you feel comfortable with) to understand the problem and then ‘translate’ this code to assembler. I remember programming a blocks world simulation in MIPS assembler like this.

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

Sidebar

Related Questions

I've never used MIPS assembly before and it was just introduced in class. I'm
I am trying to translate a C program into MIPS assembly code In my
I have this issue using assembly MIPS. From the keyboard I read an integer
When I learned MIPS assembly a few months ago, a question popped into my
In my MIPs Assembly Programming class I've been tasked with writing a program that
I'm writing a subroutine in MIPS assembly language to convert ASCII into UTF-16 and
I'm writing a MIPS assembly code that will ask the user for the file
I'm trying to create an array in MIPS Assembly, and then add all the
I'm trying to get my feet wet with MIPS assembly language using the MARS
Trying to convert this c code into MIPS and run it in SPIM. int

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.