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

learn more… | top users | synonyms

4
votes
2answers
74 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
51 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
153 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
23 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 ...
3
votes
3answers
122 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
78 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\$ \$...
1
vote
0answers
21 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
282 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
36 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
81 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
96 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 ...
4
votes
1answer
222 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
101 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
97 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
170 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
157 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
195 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
100 views

Infix to postfix parser in java

Please review my Parser class. Should I declare map outside of convToPosfixQueue method? ...
10
votes
3answers
282 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 ...
2
votes
1answer
90 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
139 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
189 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 → / ...
4
votes
2answers
125 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
49 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 ...
10
votes
2answers
2k 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 ...
10
votes
1answer
117 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
1answer
182 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
463 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
884 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 ...
3
votes
2answers
378 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
207 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
264 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
90 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. ...
7
votes
2answers
1k 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
51 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
78 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 ...
1
vote
1answer
3k 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
1k 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
3k 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
4k 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
371 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
454 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
786 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
326 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
3k 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
183 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
4k 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
3k 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
147 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
74 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 ...