FAQ Database Discussion Community

C++ Mathematical Expression Parser Issue

#include <iostream> #include <string> #include <queue> #include <stack> #include "NodeType.h" using namespace std; // Test if token is an operator bool isOperator(char token); int getPrecedence(char token); bool comparePrecedence(char tokenA, char tokenB); int main() { stack<char> tokenStack; queue<char> tokenQueue; string expression= "", postfix= ""; char x; cout<<"Please enter a mathematical expression:...

Infix operator with missing argument

Is it possible with Haskell to have an operator (infix function) working with a missing argument ? (rather like - meaning a subtraction or a negative sign) For example, I have this operator : data1 <*> data2 Is it possible to make it work with a default value if first...

Javascript pushing operators to a stack from a string

I am currently writing a program in Javascript where the user enters in an infix notation expression as a string which will then be converted to postfix notation. I'm having trouble pushing each operator to the stack. Below are the two main portions of code pertinent to my question. var...

Haskell priority of operator

I have some questions about priority of operators with Haskell. Is infixl the correct way to set an infix operator priority ? Is it possible to modify the priority in its own programs ? What is the difference between infixl and infixr ? ...

Shift/reduce conflict with infix sections

I'm having trouble with a yacc-like implementation (using ocamlyacc, in particular) of a grammar that includes ordinary infix operations plus infix sections, like in Haskell. I desire all of these to be grammatical: (+1) (1+) (+) (1+1) However, I haven't been able to get this working, even by fiddling with...

infix to postfix in java using stack class

I'm trying to write infix to postfix program in java using stack. Here is my code: import java.io.*; import java.util.*; public class ONP{ public static void main(String args[]) throws java.io.IOException, NumberFormatException ,EmptyStackException{ BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); StringBuilder out= new StringBuilder(); Stack st=new Stack(); for(int i=0;i<n;i++){ String input=br.readLine();...

Why is f <$> g <$> x equivalent to (f . g) <$> x although <$> is not right-associative?

Why is f <$> g <$> x equivalent to (f . g) <$> x although <$> is not right-associative? (This kind of equivalence is valid in a popular idiom with plain $, but currently $ is right-associative!) <*> has the same associativity and precedence as <$>, but behaves differently! Example:...

Does Scala provide an easy way to convert Infix expressions to postfix ones?

I a beginner in Scala and I am writing a program in Scala to convert infix arithmetic expression to the postfix one meanwhile wondering whether Scala provided an easier way to handle these kind of conversions. Can anyone guide me if there is any easier way for it?