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
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 ...
14
votes
3answers
1k views

Equation Evaluator

I am currently applying to many Software Engineer positions, and have been asked to complete several coding challenges. The most recent was an equation evaluator, written in C++, that was supposed to ...
14
votes
2answers
4k views

Evaluating arithmetic expressions

I have written some simple code for evaluating expressions. However, I am not sure how well I am following conventions (this is my first time trying to). Specs for problem: All binary operators (+, -...
13
votes
3answers
20k views

Math expression solver

I've recently stumbled upon an interesting challenge for me: You should develop C application, that solves math expressions. Operations such as (+,-,*,/) should be supported, as well as (cos, sin, ...
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
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 ...
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 ...
11
votes
1answer
568 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 ...
11
votes
1answer
1k views

Math expression evaluator

It is my second attempt to make a math expression evaluator. To evaluate an expression, I created a class that works like this: -it removes all the blank spaces -if brackets are present, it ...
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 ...
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 ...
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 ...
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 <...
10
votes
4answers
893 views

Validator for mathematical expression in infix form

This program will validate whether a mathematical expression entered by the user is a valid expression based off whether the expression itself has been entered with the correct scope openers and scope ...
10
votes
3answers
1k views

Parsing expression with exponents and evaluating

I'm programming a basic command line calculator in java that can parse expressions and evaluate them, does not handle brackets yet. For example an expression: \$9+9/2^2*5-1\$. At this point I can ...
10
votes
2answers
135 views

Synthetic division calculator

I've written a python program do perform synthetic division on a polynomial. There are a few constraints (listed in the module docstring of the program) on the polynomial, mainly because I haven't had ...
9
votes
3answers
6k views

Python calculator taking string input

It accepts string input like '1+1' instead of num1 = 1, num2 = 2, operation = '+' or something like that. ...
9
votes
2answers
33k 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 ...
9
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 ...
9
votes
1answer
6k views

Creating truth table from a logical statement

This code creates a truth table from a statement in logic. The statement is input as a string, and it is identified as a tautology if it is true for all true and false combinations of the variables. ...
8
votes
3answers
315 views

If ComparisonIsTrue(thisPost, ComparisonOperator.NotEqualTo, goodCode) Then Me.Answer

This is a follow-on to a global enum for comparison operators. I wanted to pass a logical expression E.G. >= someValue as a parameter to a function, so I made an ...
8
votes
1answer
4k views

A queue based calculator for basic math operations

Currently, I am interested in programming. I have programmed a calculator in C. Everything works, but I do not feel completely confident in my solution. Are there any logic or efficiency issues with ...
8
votes
1answer
375 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: ...
8
votes
3answers
556 views

CodeWars mathematical expresion evaluator

I recently wrote the following code for a codewars.com kata for evaluating mathematical expressions. I've been writing ruby for years, but almost everything I do is for personal use and isn't shared,...
7
votes
3answers
3k views

Console calculator, takes a string as input (like: 2+3*4-1+3) and outputs the result

I am a beginner programmer(solo learning). I know the basics of c/c++, but I would not consider myself too experienced. Recently I decided to make this calculator which takes an array of characters as ...
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
4answers
9k 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 ...
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 ...
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 ...
7
votes
3answers
3k views

Building abstract syntax tree for markargs

Roadmap I'm trying to follow usual compiler design: Lexical analysis (1, 2) Syntactical analysis <---- you're here Semantic analysis User input Code generation + execution Background I think I ...
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: ...
7
votes
2answers
317 views

Tokenize and detect syntactic errors in simple math expressions

I thought that I didn't learn anything new for over a month or two, so I decided to start off with compilers. The code is really crappy, but at least it works. Problem definition: Given a bunch of ...
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 ...
7
votes
1answer
53 views

Infix to postfix conversion in C++

Here is a program for conversion of an infix expression to a postfix expression using a stack. I would like to know how I could improve my checking for invalid input, make my code more expressive, and ...
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 ...
7
votes
1answer
854 views

Infix to postfix converter

I've written this infix to postfix converter using this website as an helper. At the end of the web page, there is the procedure for the algorithm. A summary of the rules follows: Print ...
7
votes
1answer
54 views

Arithmetic/Geometric series calculator

I've written a small program that calculates Arithmetic and Geometric Partial Sums. I'd like feedback on anything possible, since I intend on writing a cheatsheet that encapsulates all PreCalculus ...
6
votes
4answers
12k views

Polish notation interpreter/calculator

Just for the heck of it, I wrote a simple little interpreter that takes in inputs in the form of Polish Notation. The user will input something like + 5 6 And ...
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 ...
6
votes
2answers
13k 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 ...
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 ...
6
votes
2answers
5k views

Expression parser using the shunting yard algorithm

I am trying to implement an expression parser via the shunting yard algorithm about which I learnt here. I am able to get the correct results for the cases I'm testing, but I think it would be better ...
6
votes
2answers
97 views

JavaRPN calculator

I have found that there is a distinct lack of an RPN calculator available to me, so I decided to make my own. I am still adding new functions to it, but as of now, I would like to refactor my code. ...
6
votes
3answers
117 views

Postfix calculator in Java

I made a postfix calculator in Java. The code performs the functions I planned without problems, However, I'm not satisfied with it, because it's too verbose and I couldn't split it up into methods ...
6
votes
2answers
497 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: ...
6
votes
1answer
90 views

Shunting-yard Algorithm, implemented based on reference pseudocode

I have a lot of problems making this code look more elegant or to reduce its size. The algorithm is mostly copied from the pseudocode of wikipedia page. The difference is I prepare my string with the <...
6
votes
3answers
129 views

Evaluating a math expression given in string format

I am currently working on building a calculator using Java and JavaFX to practice my coding skills. I wrote the following methods to evaluate a given expression. What can I improve? Is there ...
6
votes
3answers
1k views

Reverse Polish Notation calculator with unit tests

I had an interview with a global company yesterday. They had given me a programming assignment. I shared my screen and I must have finished the task in 1.5 hours. Task was programming Reverse Polish ...
6
votes
3answers
587 views

Simple parenthesis removal - JavaScript

I solved the following problem: You will be given a mathematical string and your task will be to remove all braces as follows: ...
6
votes
1answer
1k views

Java OO Design - Reverse Polish Notation Calculator

The following is my implementation of Reverse Polish Notation. I should have mentioned that this is for a coding question, which asked for unary, binary, ternary, etc. operations that also allows user-...