The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
7
votes
1answer
898 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
144 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
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 ...
5
votes
1answer
175 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
326 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
97 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
270 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
1k 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
1k 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 ...
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 (+, -...
3
votes
1answer
599 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
1k 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
327 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. ...
5
votes
1answer
1k views

Reading integers and evaluating an arithmetic operation in a string

This Java code is reading integers and arithmetic operations from a string and evaluating the arithmetic operation. For example: For the input "32+54*27*4/13", ...
6
votes
1answer
242 views

Expression evaluator with Shunting-Yard algorithm

I am especially concerned about: Correctness: Does my algorithm always output the correct answer given a correct input? Readability: Is my algorithm easy to understand for an experienced Ruby ...
2
votes
2answers
1k views

Infix expression (with negative numbers) to postfix

I am writing a class to evaluate an arithmetic expression, For now my class can convert an infix expression into postfix, it doesn't support exponents yet. ...
1
vote
3answers
222 views

Calculate the value of an arithmetic term written in Polish Notation

I have to create a program which calculates the result of an arithmetic term written in Polish Notation. ...
5
votes
2answers
692 views

Optimize shunting-yard algorithm

Following your suggestions, I updated my expression evaluator with a Shunting-Yard algorithm. I've created two classes, a Shunting-yard class and a RPNsolver class. The first I mentioned converts ...
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 ...
1
vote
1answer
1k views

Tokenize a mathematical statement string

The function tokenize generates tokens from a mathematical string. It can chain characters together to form longer tokens. This can be used to build a parse tree,...
9
votes
1answer
7k 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. ...
3
votes
1answer
541 views

NASM RPN Calculator

I've been learning Assembly over the past few days, and I've made a simple RPN calculator. Here is the main logic of the program, excluding utility functions such as printing: ...
5
votes
1answer
4k views

Shunting-yard algorithm for expression parser

After reading about the Shunting-yard algorithm, I decided to try to make a expression parser, before trying to make a actual language parser, using it. The way i translated the algorithm into C++ ...
4
votes
1answer
499 views

Rust Console RPN Calculator

I've been trying to teach myself Rust, and I decided that a simple console calculator would be a good project to learn from. ...
3
votes
0answers
83 views

Parser for an bifurcation analysis tool

So during my thesis I used xppaut quite extensively. In the end there were some minor problems and I decided to have a look at the code, which was just released at github. So after 30 years of on and ...
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 ...
5
votes
2answers
3k views

Postfix calculator

As part of my learning Java I'm doing various tasks I set myself - one such task is a postfix calculator. It seems to work with all tests I've given it, and I would really appreciate some review of ...
2
votes
1answer
103 views

Interpreting a basic math string

I've written code that will take any basic math sum input as a string (for instance, 2*3+4/4) and solve it. The way I achieve this is by splitting the string into ...
5
votes
3answers
667 views

A command-line calculator using infix to postfix in C++

I was in the mood for some C++ and decided to write a command line calculator, which understands addition, subtraction, multiplication and parentheses. See what I have: main.cpp ...
3
votes
2answers
3k views

Evaluating a completely parenthesized arithmetic expression

I tried to solve the following problem in a programming challenge, but the verdict was time limit exceeded. Completely parenthesized expression Write a program that reads a completely ...
4
votes
2answers
137 views

Mathematical input parser

I made a simple math expressions solver that using a "for" loop iterates over all the characters and stores the numbers and signs in std::vector. It give support for unlimited parentheses and does ...
1
vote
1answer
1k views

Math expression parser in JavaScript

I've written the second iteration of my math expression parser, utilising what I learned from the first attempt to make a more reliable, maintainable piece of code. If anybody wants to see the first ...
2
votes
4answers
932 views

Reverse Polish Notation Evaluation in Java

I would like to hear feedback about my code both in term of improving efficiency if possible or using other data structures. Also go ahead and let me know about code styles/patterns. ...
3
votes
1answer
865 views

Mathematical equation syntax tree

I'm writing these pieces of code to parse expressions in the context of a dice rolling application for DnD. It's pretty much my first try using TypeScript and I'm ...
4
votes
4answers
2k views

Primitive console string calculator in C

Recenlty I have finished this primitive console string calculator in C. I need your balanced criticism, I'd like to know what I have to correct, remake and learn. Permitted operations: ...
6
votes
1answer
221 views

Data structure for expression evaluation in Haskell

I've made a data structure for mathematical expressions. I want to parse mathematical expressions like: \$x = 3\$ \$y = 4\$ \$z = x + y :\$ into an evaluated document like: \$x = 3\$ \$y = 4\$ \$z =...
3
votes
1answer
96 views

Grouping all mathematical results using a number sequence with basic math operators

Not sure how to make the title smaller. I was reading the question A truly amazing way of making the number 2016 and some of the answers referred to programatically determining the answer set. What ...
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 ...
5
votes
1answer
280 views

Parsing/RPN calculator algorithm

I decided to try and complete the Parsing/RPN calculator algorithm from Rosetta Code in Rust. I'm still learning Rust and would appreciate feedback on my code. ...
4
votes
3answers
911 views

Math eval function for Haskell

I recently finished reading Learn you a Haskell for great good!. Even though some topics are a bit over my head (Monads anyone?), I wanted to try my hand at a ...
3
votes
0answers
687 views

Expression parser using Shunting-yard algorithm

I've been working on a expression parser which will be part of another project (some sort of DSL). This parser basically uses the Shunting-yard algorithm, except for the case of parenthesis: here it ...
5
votes
1answer
19k views

Reverse Polish Notation Calculator in Java

I created a highly effective Reverse Polish Notation calculator using Java 8, but am uncertain if there are any better ways to handle the problem. Feedback on any evident taboos and bugs is greatly ...
8
votes
3answers
570 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,...
6
votes
1answer
1k views

Somewhat Advanced C++ Calculator

I am currently in the process of learning C++ from C++ Primer. I have found the exercises in this book to be somewhat dull in that they only test syntax and not reasoning. As such, I have recently ...
4
votes
1answer
932 views

Simple lexical analysis - basic calculator

I recently found an interesting series that describes the specifics of how interpreters and compilers work, explaining each step (with code) and encouraging the reader to do exercises. My code is ...
0
votes
2answers
6k views

Infix to postfix implementation using a stack

I have implemented a "infix-to-postfix" function that takes as input a list representing the parsed expression, resulted from applying a certain regular expression to an expression, and I would like ...
5
votes
1answer
605 views

Basic arithmetic operations for a programming language

I have written a set of functions to compute basic mathematical operations for my own Java-based programming language. First I tokenize input from the source code file and store it in a String array. ...
-1
votes
2answers
353 views

Infix to postfix parser in java

Please review my Parser class. Should I declare map outside of convToPosfixQueue method? ...
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 ...