Questions tagged [math-expression-eval]

Questions related to the parsing (and possibly the evaluation) of free-form mathematical expressions in strings, lists, or streams

Filter by
Sorted by
Tagged with
2
votes
1answer
846 views

Postfix evaluation using a stack in c

I have written a program to evaluate a postfix expression using a stack. I had my stack implementation using a linked list reviewed here, so I am only including the header file here. I have taken ...
4
votes
1answer
1k views

Infix to Postfix Formula Parser Java

I've written a program that takes a mathematical formula as an user input and converts it from infix to postfix. It doesn't support negative numbers. The program doesn't depend on the user having to ...
4
votes
1answer
1k views

Ad-hoc lexical scanner for a calculator language

Challenge: Build an ad-hoc scanner for a calculator language. Specifications: The tokens for the language are as follows: assign → := plus → + minus → - times → * div → / lparen ...
4
votes
2answers
392 views

Reverse Polish Notation in F#

In my question to learn F#, I've decided to get one step closer to creating a programming language, and implement this simple Reverse Polish Notation "interpreter" of sorts. It does not allow for ...
3
votes
0answers
103 views

Expression parsing (arithmetic operators only)

As a self-learning project, I wrote an expression parser using the shunting yard algorithm in JavaScript. It's a larger part of what I plan to be a program for handling dice expressions in tabletop ...
12
votes
2answers
10k views

+, -, *, /, () expression calculator

In an effort to understand how compilers work, I wrote a simple expression calculator in C#. A CalculatorExpression takes an infix string, converts the infix string ...
11
votes
1answer
167 views

Mathematical expressions evaluator with callbacks, the architecture

This question goes hand in hand with another question about a mathematical expressions evaluator in C++. The other question is meant to be read first, this one is but a complement to expose the ...
11
votes
1answer
575 views

Mathematical expressions evaluator with callbacks, the logic

I hesitated quite a bit of time before posting this question since the code to review is more or less a monster (with regards to its size). It is a basic mathematical expressions evaluator, but with ...
7
votes
2answers
1k views

A (late) Simple Calculator

As I was looking through my past questions, I noticed my really old calculator question (here and here). Considering it looked like a huge mess, I decided to rewrite it. Coincidentally, the April 2015 ...
11
votes
3answers
1k views

CC C# calculator

This is my basic C# calculator; I'm sure there is much that can be improved. This design is based on Bjarne Stroustrup's C++ calculator, a purposely be-bugged version of which can be found at his ...
4
votes
2answers
2k views

Recursive math expression eval

It has been very hard to use recursion, but I think that it made the code shorter and cleaner. ...
8
votes
1answer
382 views

Parsing equations from stdin

The program should read equations from stdin, parse them and generate a matrix of the coefficient which represents the system. Example: ...
6
votes
2answers
1k views

Calculator that parses S-expressions

This is my first program I can call 'something'. I would be glad to hear what you think of it, so I wouldn't pick up bad habits further on. It catches errors, but requires numbers to be separated ...
4
votes
1answer
333 views

Evaluating an expression with integers, +, and *, as well as -, / - revision 3

The original question came from this web site. Revision 1 Revision 2 And this is the third revision. I delete spaces and validate an equation before computing. ...
9
votes
2answers
35k views

Evaluating an expression with integers, +, and *, as well as -, /

There is a job interview question, and the source of the question is here. The solution is pretty simple. We just need to split the input string by + and then by *. Then we compute products in a ...
3
votes
1answer
214 views

Reverse Polish Calculator in Go

I'm very new to Go (this is my first real program), and I was hoping to see if there was anything I was missing about the language or any ways to make it more idiomatic. calculator.go ...
4
votes
4answers
102 views

Math expression on-the-fly interpreter

In the last few day, I wanted to sharpen my C skills a bit, so I wrote a math expression interpreter that can handle + - * / ( ) and only integers. I just want to know how good this code is, if ...
2
votes
1answer
15k 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
5k 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 ...
4
votes
2answers
11k 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 ...
8
votes
4answers
10k 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
1k 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
1k 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
3k 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: <...
6
votes
2answers
526 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: ...
11
votes
2answers
5k 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
559 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
14k 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 ...
15
votes
3answers
1k views

Reverse Polish notation based compiler

Description Very small subset of Forth This is a proof of concept level compiler, no optimizations or over/underflow checking See the embedded POD for more information NASM is used as assembler gcc ...
10
votes
3answers
8k 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
169 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
169 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 ...
5
votes
2answers
640 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 ...
4
votes
2answers
926 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 ...
2
votes
1answer
727 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 ...
6
votes
2answers
29k 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 in ...
7
votes
1answer
1k 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 ...
1
vote
5answers
22k 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. ...
7
votes
2answers
12k 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
420 views

Simple Calculator - revised

This is my revised code of the Calculator: ...
10
votes
2answers
1k 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 <...
7
votes
1answer
17k 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 ...
6
votes
1answer
2k views

Reverse Polish Notation Calculator

Working through Learn You a Haskell, I made a Reverse Polish Notation calculator. Please critique it. ...
4
votes
1answer
64 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, <...
10
votes
4answers
9k 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
6k 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
598 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 ...
7
votes
2answers
3k 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
7k 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 example: ...
11
votes
1answer
4k views

Recursive calculator in C

This is a calculator I wrote for a student's project. It still has a problem (one that I know of), where it can't handle inputs of the form 2*2*2... (more than one ...