Creating calculator in abap - algorithm

I've build a basic calculator in abap which is pretty simple and knows how to get 2 inputs and calculate them by pressing a push button of the operator( + - / *).
Now I want to make a calculator which gets one input like : "12+5*3-9"
But I really don't know how to start it.
Can anyone help me a little bit please?
Thank you.

You question is related with an algorithm for parsing mathematical strings rather than ABAP. One of them is Shunting-yard.
If you need to short way, you can add your expression into java script function and run it in CL_JAVA_SCRIPT class in ABAP.
Check example ABAP program DEMO_JAVA_SCRIPT_MINI_EDITOR.

Related

Diagramming Decision Trees

I have been a self-taught coder for a long time, and I am asking for help with a conceptual problem here. I can solve this particular issue myself, but I feel like these problems always take me too long with trial & error solutions. I believe there is a way to Diagram this type of problem, but I don't know what it is called or how to look up this solution.
When I have multiple, often inter-dependent pre-conditions to a conditional outcome like as follows, it takes me forever to figure how to arrange my conditional statements:
I have a set of Values called: "Tab Numbers". Let's say I have 4 pre-conditions:
All Tab Numbers are blank
Some Tab Numbers are blank
A Session Boolean flag called SuppressPrompt is True
This Method is being called during the Open Session Event
These Pre-conditions determine my 3 desired outcomes:
A) Prompt for User Input
B) Auto-Populate Tab Numbers
C) Do Nothing
Now some of these pre-conditions affect other possible preconditions:
Eg.: The the Flag in Condition #3 cannot be set if the method is being called in the Open Method Condition #4.
I believe there is a good way to diagram these types of problems so that I don't have to puzzle through them with Trial & Error every time. Can anyone help point me to a resource to learn how to do this easier?
I am sorry if I am not posting this in the right place, but it is a problem that I keep running into. If anyone could just help point me in the right direction, I would really appreciate it.
Your truth table may look like this:
Preconditions Outcomes
AllBlank SomeBlank SupPrompt OpenSession UserInput AutoFill Notes
T T [T] T ? ? Impossible
T T T F ? ?
...
F F F F ? ?
You will hopefully see some non obvious correlations, which will allow you to simplify your table, possibly splitting it, until you get the logical expression(s) you need

Trying to design a Gui based Boolean logic to Boolean Equation program

my job is in automation and I deal a lot with Boolean logic for when a piece of equipment has permission to do something or not do something. this requires that I design expressions in simple one line equations. I'm trying to figure out how I can design a little helper app to make it easier to code.
For example, let's say I'm trying to design a permissive to allow a vehicle to start moving, just jumping into a car won't make it start going, there steps that need to happen before the car will go any where. such as turning on the motor. i'f you look at the image below you can kind of get an idea of a simpler equation.
https://i.ibb.co/fnQ3x9x/IMG-2389.jpg
The eq for the picture is:
Start Permission = MotorTurnedOn AND ((AutoMode OR (ManualMode AND (OilTempNorm OR OilCoolingActive))) OR EmerOvr)
A lot of time I'm editing code that someone wrote a long time ago so it's not always easy to understand and some are very long as seen in the picture below
https://i.ibb.co/tXtrKwk/IMG-2388.jpg
the picture are generated by a third party software that is used to create the GUI's for the equipment.
I'm trying to figure how how could I design something where I could take block and drop them into something resembling the picture and it could export an equation for the equivalent boolean expression.
I'm only familiar with Python, Matlab, C++ and a little bit of java, if there's some template out there that could help me get started I'd be willing to learn a new language otherwise, i'd wanna stick closer to what I know.
Any help or ideas would be appreciated.

UIPath. Vb.net? if condition

Im new to uipath and coding in general. I know most of the basics from what was taught but they didnt go through how to form "condition" statements in the "if" activity. or basically any form of conditions. Where can i go about to learning them? is it a specific language?
kinda like: not Months.Contains(ExpenseMonth)
i wouldnt be able to come up with that because i dont know what is acceptable/readable to uipath studio
also regarding those calculations. where can i find more information on those? to learn more about
kinda like: (int32.Parse(row("Value").ToString) * 100 / monthlyTotal).ToString
they didnt really give me details on how to form that
so essentially, if i wasnt spoon fed with those statements, i would be stuck
It depends on which activity you are using. Usually it's VB.net. Find more about that programming language here.
And yes you will need to get the basics of that language on your own. UiPath isn't really helping you find the correct condition. It is more a tool that can use VB.net.
And soon you can switch to C# completely. But that is not yet ready and still experimental. Also, I would recommend you to stay with VB.net as it is way easier to learn as a first language. Currently, you can only use C# and Invoke Code activity.
To your first example from above:
not Months.Contains(ExpenseMonth)
That depends on your variable type. That looks like a DateTime or a String type and so you are able to use predefined functions that come with it. You can show them but simply clicking CTRL + SPACE after the dot.
And your second one:
(int32.Parse(row("Value").ToString) * 100 / monthlyTotal).ToString
I would always recommend you to use CInt instead of int32.parse. Look here. And it is often not needed to convert the row value into a String. As it is usually already in that type by default.
But again. You will need to learn the basics of VB.net before you are able to write a good business logic in UiPath that makes sense and is best practice.

E programming language - overview

I need a basic overview of E programming language - http://en.wikipedia.org/wiki/E_%28programming_language%29
Could please someone that has used it, or knows its syntax give me a brief example of the following things:
Declaring and assigning values to variables: integer, floating point, string.
Conditional and loop statements,
Functions - syntax, writing and using functions, example,
Arrays - syntax, definition, example
I know that there is already info about this in their website, but they seem to have just written it without much examples or explanations.
Also could you please point me to a site, where I can download an E compiler, in order to play a little bit with the syntax and get some exercise in writing basic programs (the links in their website are all broken/moved etc.)
Thank you for your time.
Best regards!
you can use the link
e programming

Delphi, evaluate formula string

Duplicate
Best algorithm for evaluating a mathematical expression?
mathematical expression parser in Delphi?
I need a program in Delphi that get one variable equation from Edit1 such as "F(x)=4*X+2*log(x)+4*power(X,2)"and get X value variable from Edit2 then show the result F(X) in Edit3. Please help me.
Thanks.
You probably need to have a look at this component - TbcParser.
http://www.bestcode.com/html/tbcparser.html
This component has source code included.
You can also check out JCL, which comes with an expression evaluator in the file JclExprEval.pas. It's free and open source.
Have a look at
http://www.efg2.com/Lab/Library/Delphi/MathFunctions/Parsers.htm
Also, if you have JEDI and/or FastReport libraries installed you can use their parsers. We use TParser10 from http://cc.embarcadero.com/item/15974 which is one of the fastest available if not the fastest. It is freeware and work flawlessly up to D2007. I heard that it works also in D2009. Not tested yet though.
If you want to write an own implementation and not use a ready to use library this will take you some time to do. Just search for "formula parser". I would start with a tokenizer and then build a parse tree from the tokens.
It STRONGLY depdends on your decimal separator. Use StrToFloat or in newewr versions of Delphi - TryStrToFloat.

Resources