Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [math-expression-eval]

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

4
votes
1answer
93 views

Writing monadic Haskell to evaluate arithmetic expression

I have been studying Haskell by myself for about a little over a year. And I have been stuck at monad/monad transformers for quite a while until recently some examples I read online enlightened me. So ...
2
votes
1answer
49 views

Python implementation of Conway's chained arrow notation

A year ago, I implemented an evaluation algorithm for Conway's chained arrow notation in Python. I'd like to get a review on my code, especially about readability and if it is pythonic. I'd also like ...
3
votes
1answer
64 views

Infix to postfix notation in Haskell (Shunting-yard algorithm)

I've written an infix to postfix converter in Haskell using the Shunting-yard algorithm. Example of how it works: ...
1
vote
1answer
66 views

Reverse Polish Notation evaluator in Haskell

I've created an RPN evaluator in Haskell, as an exercise because I'm new to this language. It runs well: $ ./rpn 2 3 4 5 + - + -4 And the source code: ...
1
vote
1answer
48 views

Calculate simple arithmetic string in Scala

Problem Given an arithmetic string like 2+2*3 calculate result 8. Assumptions you can make string will be always well formed (no error checking needs to be done) only operators passed in string ...
2
votes
1answer
73 views

Calculate arithmetic expression represented by a string, in Java

I saw that interview question online and gave it a try: Implement a function that gets a string which represents an arithmethic expression: contains only numbers or the the operators: '+', '-', '*', '/...
2
votes
0answers
40 views

RPN calculator in Chicken Scheme

My first attempt at Scheme (Chicken Scheme) - a simple RPN calculator. Please comment on exception handling as well as the general coding style. Here is the code: ...
2
votes
2answers
79 views

JS calculator, respecting order of operations

I have a function that receives an array of numbers and operations Ex: userEntry = [3,+,3,x,3] -> returns 12 It is a calculator that adheres to the proper ...
2
votes
0answers
84 views

Recursive descent parser for simple arithmetic expressions grammar

What I'd like to see in your review, in order of relevance: Is there any bugs? (I see none, but...) Is the code efficient? (by whatever metric you'd like to use) Is the code easy to understand? ...
5
votes
2answers
167 views

Basic arithmetic calculator with float, parentheses and operator priority support

Summary: The basic calculator which allows the end-user to calculate the value by evaluating the math expression string. It supports all the main arithmetic operators, also extended by modulo and ...
4
votes
0answers
100 views

Python expression calculator [closed]

This is a calculator I created. It can take all basic operators, including brackets. I am a beginner with Python so I want to know what can I do better next time I write something similar. ...
2
votes
1answer
161 views

Converting Reverse Polish to Infix Notation in Java

I am trying to solve a programming challange that involves converting reverse polish notation to infix notation. For example: 1 3 + 2 4 5 - + / would be: ((1+3)/(2+(4-5))) My solution so far does work,...
2
votes
0answers
180 views

Binary Expression Tree

I implemented a binary expression tree, I've used my previous shunting-yard parser to provide it the post-fix expression. I have a few specific questions outside of just comments about making it ...
4
votes
1answer
319 views

Use Infix expression to construct a binary expression tree

Problem statement Construct a binary expression using infix expression. The infix expression uses extra parenthesis to enforce the priority of operators. For example, infix expression ...
5
votes
1answer
278 views

Shunting-yard algorithm

I implemented the Shunting-yard algorithm in Python, I have experience in C# but I'm looking for comments making this more pythonic. I'm also be interested if these methods would be better as ...
0
votes
0answers
60 views

Mathematical expression parser

I am writing a mathematical expression parser. This function here evaluates only certain operators. ...
6
votes
3answers
579 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 ...
7
votes
3answers
2k 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 ...
10
votes
4answers
478 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 ...
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 ...
4
votes
2answers
1k views

Expression calculator in Python

This calculator accepts four operators: +, -, *, /, and works with parentheses. Feedback on how I could make it easier to read and or more effective would be much appreciated. This is the first time ...
6
votes
1answer
123 views

String to token vector for expression parsing

My objective is to create a linear algebra calculator that would be able calculate expressions containing vectors, matrices, (eventually complex numbers/imaginary; quaternions), and real numbers. I've ...
3
votes
2answers
142 views

CodeWars - Three-pass compiler for arithmetic expressions

I'm looking for feedback on my solution to the Tiny Three-Pass Compiler kata on CodeWars. The kata is to implement a compiler for an arithmetic language in three passes - parsing to an AST, constant ...
5
votes
3answers
390 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: ...
1
vote
1answer
110 views

Stack calculator in Racket

I have implemented a stack calculator based on this programming task. I wondered if a more experienced racketeer could give me feedback and tell me if I am missing anything in Racket that would enable ...
9
votes
3answers
4k views

Python calculator taking string input

It accepts string input like '1+1' instead of num1 = 1, num2 = 2, operation = '+' or something like that. ...
0
votes
1answer
168 views

Equation parser + solver

Here is an equation parser that I just wrote. My focus was on readability and the prospect of adding new features in the future. Since I like a somewhat functional style, I also gave type annotations, ...
1
vote
1answer
67 views

Infix to postfix Converter implementation

Please suggest some ways to improve my code for calculating a postfix expression from an infix expression entered by the user. The size of the input (Infix string) ...
2
votes
2answers
3k views

Simple calculator to evaluate arithmetic expressions

I've studied Java for 2 and a half months. Got bored and decided to make a basic calculator that takes any basic expression with 2 integers/doubles. E.g. 5.5x10, 5+5, 5-2.5, 6/2. Is this a good way ...
4
votes
1answer
403 views

Interpret English as Math and Perform Operations

The idea is to accept an English string of math operations and evaluate it from left to right. Regarding Order of Operations: when speaking operations aloud, it is often with implied parenthesis ...
1
vote
1answer
102 views

Riemann Sum Class (with variable endpoint behavior)

Here is my class for calculating a Riemann Sum. I did a cursory google search for a built-in function with these specifications but didn't find anything (I'm sure I just missed it or didn't look hard ...
1
vote
0answers
320 views

Infix to RPN converter using the Shunting-Yard Algorithm

I need to be able to parse simple equations in an app I'm writing, and decided to try writing my own parser. I ended up using the Shunting-Yard Algorithm to convert from infix notation to RPN as the ...
2
votes
2answers
1k views

Evaluate string as boolean expression for Robot Framework

I wrote this code as a part of a series of major upgrades to my nestable Robot Framework For Loop that will allow it to evaluate logical expressions written in a single cell from the Robot Framework ...
2
votes
2answers
471 views

Python PEMDAS calculator [closed]

The goal of this calculator is to evaluate an expression with PEMDAS in mind (no parenthesis yet, adding soon). Although the program works, I want to make it as efficient as possible with the approach ...
1
vote
1answer
344 views

Analyzing an arithmetic expression using stacks

I'm looking for some constructive (harsh) criticism of a homework I've done (the code works fine). Also Is there a better/another way to solve the exercise? Exercise: Read an arithmetic expression ...
4
votes
1answer
85 views

Python basic arithmetic compiler

I am attempting to follow the "Let's build a compiler" tutorials, in order to build a basic language compiler for a custom assembly language. Currently the specs of my compiler are: Accepts a ...
7
votes
1answer
543 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 ...
2
votes
1answer
136 views

Overhauled AST builder for markargs

This is refactoring of the code described in the previous iteration. Roadmap I'm trying to follow usual compiler design: Lexical analysis: 1, 2 Syntactical analysis: 1, 2 <---- you're here ...
7
votes
3answers
2k 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 ...
5
votes
1answer
145 views

Overhauled tokenizer for markargs

In the previous post I've started writing a tokenizer for my imaginary programming language (which I decided to name markargs; trivia at the end of the post). Problem definition: Read the line and ...
7
votes
2answers
256 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 ...
2
votes
2answers
84 views

Basic command line REPL calculator

I'm pretty confident in this code but I want to be sure I haven't missed anything to do with optimization or error handling. The program takes input in the form of ...
3
votes
1answer
150 views

Graphing a linear equation using javascript and html

I'm open to any feedback even if it's just a quick browsing over to get a quick opinion of my code. As part of a job interview process I was given a coding challenge to complete. The challenge was ...
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-...
6
votes
1answer
702 views

Calculator/math expression parser (supporting complex numbers)

I would love some honest feedback on my latest project. I've included the part I'm guessing is most interesting, but the entire code can be found on github: https://github.com/Raincode/DeskCalc or ...
3
votes
1answer
840 views

OO design of Reverse Polish Notation Calculator

This solution focuses on the design of classes, not the actual push and pop stack part. I will include that part of the code as well. The current code has 2 operators (plus and minus). If we add ...
12
votes
2answers
2k 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 (+, -...
3
votes
1answer
332 views

Scala traits for arithmetic expressions

I am learning Scala and want to know, what is preferred style of writing a function for a trait. First: ...
3
votes
1answer
770 views

Validator for mathematical expressions in infix notation

The function belows validates if a mathematical expression, say 12 + 2 * (9 - 3) / 4, does not have operators that are next to each other. It returns ...
4
votes
1answer
277 views

Reverse Polish Notation calculator in Scala

I wrote an RPN solver in Scala. I'd love to get some feedback on approaches to make this feel more idiomatic. ...