Questions related to the parsing (and possibly the evaluation) of free-form mathematical expressions in strings, lists, or streams
1
vote
1answer
37 views
Order of operations algorithm for calculator
I wrote a simple calculator which uses orders of operations. I would like to know, do you see any serious flaws in logic and what do you think about this solution?
It is my second approach to a ...
5
votes
1answer
55 views
Calculator with order of operations
I am trying to make an additional option in my beginning calculator program, which is based on the BigDecimal class: the simultaneous solution for the entire ...
3
votes
2answers
117 views
Reverse Polish Notation calculator in Python
After reading the definition, I made a simple Reverse Polish Notation (RPN) calculator in Python.
Originally it had just 4 operators (using import operator and a ...
7
votes
3answers
509 views
RPN calculator in C
I had to write a RPN calculator in C as one of my homework problems, but if someone could critique my code and suggest any improvements, that would be fantastic! I haven't added any overflow errors or ...
2
votes
1answer
83 views
Mathematical expression evaluator and equation solver
I'm trying to implement a mathematical expression evaluator and equation solver, and based on extensive online research and my own experimentation have come to the conclusion that the best way of ...
4
votes
2answers
87 views
Java calculator for long calculations involving positive integers
I'm making a calculator that can solve calculations that are inputed in a very raw form. Say: "3*52+11+3/2"
I'm using the console, at least for now.
This will also take in consideration that ...
5
votes
3answers
435 views
Truth Table Calculator
In of my software engineering classes, I had to write a truth table calculator in the language of my choice. This is what I came up with, and I would like to know what I should do better next time:
...
5
votes
2answers
192 views
Julia RPN calculator algorithm ported from Python version
I've just finished the Reverse Polish Notation task in Julia from rosettacode.com by porting the existing Python code.
There are only a few lines I don't get how to port:
...
7
votes
1answer
552 views
Math expression parser in C#
EDIT: Added refactored version 2.0 to the end!
I have a parser that is supposed to take a string similar to a math expression and return a Tuple of:
An array of strings where each string ...
3
votes
2answers
54 views
Ruby infixed math parser
It only does expressions with 2 operands yet, but I'm wondering if there are any ways I can improve this:
...
6
votes
2answers
344 views
Basic C# calculator (+,-,*,/) - V2
Original question:
Basic C# calculator (+,-,*,/)
My 'teacher' requested this problem be solved by parsing the input into a tree based on the order of operations. The class Calc variables are ...
10
votes
3answers
416 views
Basic C# calculator (+,-,*,/)
My 'teacher' requested this problem be solved by parsing the input into a tree based on the order of operations. The class Calc variables are specific to his ...
3
votes
1answer
93 views
Evaluating given numbers and operations
The program reads in an operation, and then numbers, and does stuff to them based on that.
Exercise number 1 at this linl
For example, ./this_file sum 1 2 3 would ...
4
votes
1answer
51 views
Safe Reverse Polish Notation
I implemented the following (what I believe to be) safe Reverse Polish Calculator.
Now I'm using foldM to take advantage of the power of Monads. Previously, I was ...
4
votes
2answers
145 views
Evaluating algebra expression using an auxiliary VB class compiled on the fly and consumed in a C# project
I want to create algebra evaluator but I don't want to write my own parser because it takes much time to learn.
I don't like algebra expression in C# because it does not look natural compared to VB ...
3
votes
2answers
167 views
Creating polls and calculator with custom functions and without any global variable
I solved this problem using custom functions and calling them in main function. The challenge was to avoid global variables. Please note that I'm C++ noob and this program is fairly large. I'm ...
1
vote
0answers
69 views
Infix epression evaluation
I'm looking for some feedback on my OCaml implementation of some methods to translate infix expressions to postfix and then evaluate them.
I'm very new to OCaml, coming from C#/Java and JavaScript ...
5
votes
2answers
5k views
Infix to Postfix Converter Program
This is my homework. Kindly help me check it?
The instructions are:
Implement an infix expression to postfix expression converter. You are to implement the infix to postfix algorithm presented ...
6
votes
1answer
152 views
Predictive recursive descent parser for math expressions
I've been learning about language theory and parsing, and decided to write my first parser: a LL(1) recursive descent parser. But actually, it does a little more than just expressions; it can also ...
-2
votes
3answers
505 views
Arithmetic operation from string
I have a string like str = " 4+ 6 * 30";. I have to perform an arithmetic operation on this using C#; My solution to this problem is as follows.
...
6
votes
2answers
4k views
Infix to postfix conversion
I have written a C++ program to convert an infix expression to postfix expression using recursion. I would like to know if it can be improved if possible. Can we improve it by not using a stack? I am ...
4
votes
1answer
125 views
10
votes
2answers
396 views
Four-function expression evaluator
I've been making an interpreter for my own programming language that I've been working on as a hobby. I made an expression evaluator that can evaluate simple mathematical expressions.
It understands ...
3
votes
2answers
519 views
Parsing arithmetic expressions like (x + y * a + b *z)
I have this code which I wrote to parse arithmetic expressions.
However, many people say there are problems with it but don't tell me what the problem is. Please let me know if you see any.
Note ...
5
votes
1answer
313 views
Reverse Polish Notation Calculator
Working through Learn You a Haskell, I made a Reverse Polish Notation calculator.
Please critique it.
...
4
votes
1answer
40 views
Basic Reverse Polish CL Parser
K and R Exercise 5-10
Write the program expr, which evaluates a reverse Polish expression
from the command line, where each operator or operand is a separate
argument.
For example,
...
8
votes
4answers
2k views
Simple C++ calculator which follows BOMDAS rules
This was my first attempt at making a C++ calculator. The user basically inputs an expression (I'll use \$1+1*(9*(11-1))\$ as an example) and the program searches for and creates a vector for ...
3
votes
1answer
2k views
Math equation as string to reverse Polish notation parser
I have created a console program where users type in a math equation such as 5+4-6 or (5+16(8-4))/16 that follows order of ...
3
votes
0answers
183 views
Parsing an infix notation expression and converting to reverse polish notation
I'm pretty new to Go, and I do not know the best or idiomatic ways to do most of the stuff, so I'd appreciate feedback on how to make my code better, faster or more idiomatic.
My program is a set of ...
6
votes
2answers
1k views
Cleaning up Reverse Polish Notation evaluator
I was wondering if anyone had some general clean up advice on my code. I believe that more helper functions would be my case but I could be wrong. 30 lines maximum per method is my rule. I can't seem ...
7
votes
1answer
2k views
Command line reverse polish calculator
Write the program expr, which evaluates a reverse Polish expression from the command line, where each operator or operand is a separate argument.
For ...
4
votes
2answers
1k views
Numeric expression parser - calculator
In particular, if someone could describe a better way to go from the tokenized list to the Expression tree, it would be super helpful. I would like to get rid of the casting in the parser but am not ...
3
votes
1answer
169 views
Refactoring calculator expression
I was doing a simple exercise to calculate the amount based on an expression.
For example:
(((2*2)+(3*5/5)+(2*5))) outputs 17
...
2
votes
2answers
6k views
Postfix evaluation using a stack
I just wrote the code to evaluate a postfix expression and would like it if someone reviews it for me, it works perfectly fine but I'm having trouble adding the character "=" at the end.
...
2
votes
1answer
161 views
Advanced Calculator Kata
This is the CalculatorAdvanced Kata from the Kata gem. I've just finished it and would love some feedback on my solution.
...
4
votes
2answers
152 views
Evaluating expressions with various mathematical methods
I have started to learn Java and I need your critique for my first program. It is an interpreter that can calculate any expression including abs(), ...
2
votes
3answers
1k views
Calculating postfix notation using two forms of input
My postfix program essentially allows the user two input options to calculate a postfix equation:
Confirmations after each input (after an input, the user is ask for another number, operator, or ...
1
vote
1answer
6k views
Calculator application running on a console
I have a calculator created using C# that is running on a console.
The calculator accepts a string input (e.g. 5+5) then produces the result (5+5=10). It will then prompt the user to enter another ...
2
votes
2answers
655 views
RPN Evaluator that writes the results to a text file
For homework, I had to write an RPN Evaluator and write the results to a text file. I've done all that, but it feels weird, like the writing to my results text file. It also doesn't feel efficient. ...
2
votes
1answer
765 views
Calculator parsing S-expressions
The following program is supposed to be a (command line) calculator that parses expression following syntax similar to Lisp's S-expressions.
Some examples:
$ echo "(+ 5 5)" | ./a.out
...
3
votes
3answers
1k views
RPN-Stack-Based Recursive Calculator Needs Tuneup
This function takes an array of strings and numbers and recursively processes it as a kind of "calculating program". The structure is based on Reverse Polish Notation, so the top object in the stack ...
6
votes
4answers
5k views
Reverse polish notation interpreter/calculator
Just for the heck of it, I wrote a simple little interpreter that takes in inputs in the reverse polish notation.
The user will input something like
+ 5 6
...
1
vote
0answers
343 views
Standard Algebraic Derivative Calculator
I had some difficulty with this problem, so I'm sure there is a better way. Here is the question from SICP:
Exercise 2.58
Suppose we want to
modify the differentiation program so
that it ...