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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:09:32+00:00 2026-05-10T22:09:32+00:00

I’ve written an experimental function evaluator that allows me to bind simple functions together

  • 0

I’ve written an experimental function evaluator that allows me to bind simple functions together such that when the variables change, all functions that rely on those variables (and the functions that rely on those functions, etc.) are updated simultaneously. The way I do this is instead of evaluating the function immediately as it’s entered in, I store the function. Only when an output value is requested to I evaluate the function, and I evaluate it each and every time an output value is requested.

For example:

pi = 3.14159 rad = 5 area = pi * rad * rad perim = 2 * pi * rad 

I define ‘pi’ and ‘rad’ as variables (well, functions that return a constant), and ‘area’ and ‘perim’ as functions. Any time either ‘pi’ or ‘rad’ change, I expect the results of ‘area’ and ‘perim’ to change in kind. Likewise, if there were any functions depending on ‘area’ or ‘perim’, the results of those would change as well.

This is all working as expected. The problem here is when the user introduces recursion – either accidental or intentional. There is no logic in my grammar – it’s simply an evaluator – so I can’t provide the user with a way to ‘break out’ of recursion. I’d like to prevent it from happening at all, which means I need a way to detect it and declare the offending input as invalid.

For example:

a = b b = c c = a 

Right now evaluating the last line results in a StackOverflowException (while the first two lines evaluate to ‘0’ – an undeclared variable/function is equal to 0). What I would like to do is detect the circular logic situation and forbid the user from inputing such a statement. I want to do this regardless of how deep the circular logic is hidden, but I have no idea how to go about doing so.

Behind the scenes, by the way, input strings are converted to tokens via a simple scanner, then to an abstract syntax tree via a hand-written recursive descent parser, then the AST is evaluated. The language is C#, but I’m not looking for a code solution – logic alone will be fine.

Note: this is a personal project I’m using to learn about how parsers and compilers work, so it’s not mission critical – however the knowledge I take away from this I do plan to put to work in real life at some point. Any help you guys can provide would be appreciated greatly. =)

Edit: In case anyone’s curious, this post on my blog describes why I’m trying to learn this, and what I’m getting out of it.

  • 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-10T22:09:32+00:00Added an answer on May 10, 2026 at 10:09 pm

    I’ve had a similar problem to this in the past. My solution was to push variable names onto a stack as I recursed through the expressions to check syntax, and pop them as I exited a recursion level.

    Before I pushed each variable name onto the stack, I would check if it was already there. If it was, then this was a circular reference. I was even able to display the names of the variables in the circular reference chain (as they would be on the stack and could be popped off in sequence until I reached the offending name).

    EDIT: Of course, this was for single formulae… For your problem, a cyclic graph of variable assignments would be the better way to go.

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

Sidebar

Ask A Question

Stats

  • Questions 88k
  • Answers 88k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Take a look at these: Rock the iPhone with ASP.NET… May 11, 2026 at 5:44 pm
  • Editorial Team
    Editorial Team added an answer LINQ is an ORM (albeit a fairly simple one), with… May 11, 2026 at 5:44 pm
  • Editorial Team
    Editorial Team added an answer Hardcoding is something that should be avoided as much as… May 11, 2026 at 5:44 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.