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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:47:47+00:00 2026-05-15T21:47:47+00:00

Hello everyone I’m currently implementing a simple programming language for learning experience but I’m

  • 0

Hello everyone I’m currently implementing a simple programming language for learning experience but I’m in need of some advice. Currently I’m designing my Interpreter and I’ve come into a problem.

My language is a subset of C and I’m having a problem regarding the stack interpreter implementation. In the language the following will compile:

somefunc ()
{
    1 + 2;
}

main ()
{
    somefunc ();
}

Now this is alright but when “1+2” is computed the result is pushed onto a stack and then the function returns but there’s still a number on the stack, and there shouldn’t be. How can I get around this problem?

I’ve thought about saving a “state” of the stack before a function call and restoring the “state” after the function call. For example saving the number of elements on the stack, then execute the function code, return, and then pop from the stack until we have the same number of elements as before (or maybe +1 if the function returned something).

Any ideas? Thanks for any tips!

  • 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-05-15T21:47:48+00:00Added an answer on May 15, 2026 at 9:47 pm

    Great question! One of my hobbies is writing compilers for toy languages, so kudos for your excellent programming taste.

    An expression statement is one where the code in the statement is simply an expression. This means anything of the form <expression> ;, which includes things like assignments and function calls, but not ifs, whiles, or returns. Any expression statement will have a left over value on the stack at the end, which you should discard.

    1 + 2 is an expression statement, but so are these:

    • x = 5;
      The assignment expression leaves the value 5 on the stack since the result of an assignment is the value of the left-hand operand. After the statement is finished you pop off the unused value 5.

    • printf("hello world!\n");
      printf() returns the number of characters output. You will have this value left over on the stack, so pop it when the statement finishes.

    Effectively every expression statement will leave a value on the stack unless the expression’s type is void. In that case you either special-case void statements and don’t pop anything afterwards, or push a pretend “void” value onto the stack so you can always pop a value.

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

Sidebar

Related Questions

Hello everyone I am just learning my first programming language and have just corrected
Hello everyone i need some help. I'm trying to make an application for mac
Hello everyone i am working on a project which requires me to export some
Hello everyone don't know why this code works on windows but not on linux
Hello everyone, I have some confusion regarding some Win32 API data types and macros
Hello everyone I'm currently having 2 issues with the code below: Upon return of
Hello everyone I want to ask a question about including guards in C programming.
Hello everyone I would have a value for the need to save every time
hello everyone I'm working with Eclipse under Windows XP, but I can't find there
Hello everyone i currently have this: import feedparser d = feedparser.parse('http://store.steampowered.com/feeds/news.xml') for i in

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.