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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:10:11+00:00 2026-06-08T03:10:11+00:00

I need to implement the following thing in my web-application. I know my solution

  • 0

I need to implement the following thing in my web-application. I know my solution is incorrect, but I put the code jsut to demonstrate the idea.

There is a class ‘arc’. I need to be able to assign ANY expression to this arc (e.g. a+b+c,a-c,if-then). Once expression is assigned, I’d like to be able to execute it with some randomly taken variables. Is it possible to implement such functionality in web-applications? Maybe, I should use some plug-in like MathPL? Or maybe there is an absolutely different approach to tackle such kind of problems?

class arc {

    var $arcexpression;

    function setExpression($arcexpression) {
        $this->arcexpression = $arcexpression;
    }

    function getExpression() {
        return $this->arcexpression;
    }


}

$arc = new arc();

$arc->setExpression("if a>b then return a else return b");

$result = $arc->execute(a,b);  // the function 'execute' should be somehow described in 'arc'
  • 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-08T03:10:13+00:00Added an answer on June 8, 2026 at 3:10 am

    You don’t need to implement a whole language for this. I would start by limiting what can be done, for example, limit your expressions to arithmetic operators (+, -, *, /), parentheses and if-then operator. You’ll need to enforce some sort of syntax for if-then to make it easier, possibly, the same as php’s operator ?:. After that you need to build a parser for this grammar only: to parse a given expression into a tree. For example, expression `a + b * c’ would parse into something like this:

      +
     / \
    a   *
       / \
      b   c
    

    After that you’ll just have to evaluate such expressions. For example, by passing an array into your evaluate function of type { a => 1, b => 2, c => 3 }, you’ll get 7 out of it.

    The idea of the parse is the following:

    1. Start from position 1 in the string – and call a recursive function to parse data from that position. In the function, start reading from the specified position.
    2. If you read an opening parenthesis, call itself recursively
    3. If you encounter a closing parenthesis or end-of-string, return the root node
    4. Read the first identifier (or recursively inside parentheses)
    5. Read the arithmetic sign
    6. Read the second identifier (or recursively inside parentheses)
    7. If the sign is * or /, then create the node with the sign in it and two operands as children and attach that node as the corresponding (left or right) child of the previous operator.
    8. If the sign is + or -, then find create the node with the sign in it, one of the children being one of the operands and the second node being the root of the subtree with * and / at the root (or the second operand, if it’s a simple operation).

    Getting pure arithmetic, with parentheses, working is easy; if-then is a bit more tricky, but still not too bad. About 10 years ago I had to implement something like this in Java. It took me about 3 days to get everything sorted and was in total about 500 lines of code in 1 class, not counting javadoc. I suspect in PHP it will be less code, due to sheer simplicity of PHP syntax and type conversions.

    It may sound complicated, but, in reality, it’s much easier than it seems once you start doing it. I remember very well a university assignment to do something similar as part of the algorithms class, 17-18 years ago.

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

Sidebar

Related Questions

I need to implement portable code, but I do not know how to deal
I am learning and using Web API and need to implement following Authentication mechanism
I have an iPhone application and I need to implement the following method: +(UITextView
I need to implement a web site installer for my asp.net application. The installer
I want to implement test feedback in my web application in the following manner
I am trying to implement following thing. I need to return true if any
I have the following requirement. I need to implement dll kind of thing on
I need to implement the following: There is a table A which is supposed
we need to implement the following query in such a way that we should
I need to implement in C# the following structure from ActionScript3: objectArray.push({name:Stx10,category:123 , isSet:false,

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.