infix

How do I extend infix and stack priorities to additional operators?

How would the infix and stack priorities be extended to include the operators <, >, <=, >=, ==, !=, !, &&, and ||? When parsing an infix expression, for example: P + (Q – F) / Y#, each symbol has a priority which is relevant to their order of operation. / and * have a higher priority than + and -. Here are the priorities I have/underst...

Is it possible to add a method to a built-in type in Scala?

I would like to add a method to a built-in type (say Double), so that I can use an infix operator. Is that possible? ...

Any reason I couldn't create a language supporting infix, postfix, and prefix functions, and more?

I've been mulling over creating a language that would be extremely well suited to creation of DSLs, by allowing definitions of functions that are infix, postfix, prefix, or even consist of multiple words. For example, you could define an infix multiplication operator as follows (where multiply(X,Y) is already defined): a * b => multipl...

Code Golf: Evaluating Mathematical Expressions

Challenge Here is the challenge (of my own invention, though I wouldn't be surprised if it has previously appeared elsewhere on the web). Write a function that takes a single argument that is a string representation of a simple mathematical expression and evaluates it as a floating point value. A "simple expression" may in...

What is easiest way to calculate an infix expression using C language?

Suppose the user inputs an infix expression as a string? What could be the easiest ( By easiest I mean the shortest) way to evaluate the result of that expression using C language? Probable ways are converting it to a postfix then by using stacks.But its rather a long process. Is there any way of using functions such as atoi() or eval()...

Is it possible to use the pipeline operator to call a method on a returned object?

Is it possible to call a method on a returned object using the pipeline infix operator? Example, I have a .Net class (Class1) with a method (Method1). I can currently code it like this: let myclass = new Class1() let val = myclass.Method1() I know I could also code it as such let val = new Class1().Method1() However I would like t...

Help optimize my RPN evaluation function

Guys, My parser evaluates PEMDAS expressions by first converting from infix to postfix then uses the standard postfix evaluation rules. I parse the expression and store the tokens in a list. This precompilation is ok for me since I plan on caching the precompiled functions. I am trying to optimize the evaluate function (See Evaluate0...

Writing expressions: Infix, Postfix and Prefix

Greetings, My task is to write an app(unfortunatly on C) which reads expression in infix notation(with variables, unary and binary operators) and store it in memory, then evaluate it. Also, checks for correctness should be performed. for example: 3*(A+B)-(-2-78)2+(0A) After I got all values, program should calculate it. The ques...

Expression Tree to Infix: Null in one instance, but not in another?

I have an expression tree class, which has a method buildExpressionTreeFromQueue. As its name suggests, the method takes a queue (just a series of operators and operands) and cycles through it, adding nodes to the tree appropriately. My problem is this: when I try to write the tree as Infix notation (or Prefix or Postfix for that matter...

prefix to infix on stack

I'm trying to implement prefix to infix in c++, that's what i've got so far. The input should be for example something like this: /7+23 And the ouput: 7/(2+3) or (7/(2+3)) But instead I get: (/) That's the code I wrote so far: void pre_to_in(stack<char> eq) { if(nowe.empty() != true) { char test; test = eq.top();...

C++ infix to postfix conversion for logical conditions

I want to evaluate one expression in C++. To evaluate it, I want the expression to be converted to prefix format. Here is an example wstring expression = "Feature1 And Feature2"; Here are possible ways. expression = "Feature1 And (Feature2 Or Feature3)"; expression = "Not Feature1 Or Feature3"; Here And, Or, Not are reserved w...

Scala DSL, Object and infix notation

Hello guys, in Scala, if I want to implement a DSL, is there a way to do the following: I have an Object called "Draw" which contains the function def draw(d:Drawable) how can I make it so that I can import the Object and call it outside the object like: draw ball if ball extends the Drawable trait? The problem is that I want to u...

Understanding infix method call and cons operator(::) in Scala

Hello, I'm quite new to Scala programming language, and was trying something out stucked in my mind while I was following the lecture notes at here. I think I couldn't really understand how cons operator works, here are some things I tried: I've created a pseudo-random number generator, then tried to create a list of one random value...

Postfix to infix with unary/binary operators

I am trying to make a converter from postfix to infix notation and need some help. There is already a question about infix-to-postfix conversion, which gives an example I am failing to convert back. (Note: a minus sign is missing there!) The following is the output of my converter, where the 1st "column" is postfix input, the 2nd is my ...

Which of the following postfix notations correctly represents infix sum 1+2+3+4?

I am testing an infix-to-postfix-to-infix converter and found some kind of uncertainty. For example, a simple infix sum 1 + 2 + 3 + 4 can be converted to postfix one 1 2 + 3 + 4 + assuming that operators with equal precedence are not accumulated. If they are then I get 1 2 3 4 + + + On the other hand, all the following postfix e...

What do Push and Pop mean for Stacks?

long story short my lecturer is crap, and was showing us infix to prefix stacks via an overhead projector and his bigass shadow was blocking everything so i missed the important stuff he was referring to push and pop, push = 0 pop = x he gave an example but i cant see how he gets his answer at all, 2*3/(2-1)+5*(4-1) step 1 Reverse...

infix to postfix

Hi all, I've been trying to figure out this problem. I have an assignment to make a basic calculator. To do so i need the instructions in postfix. I have found some code online, which worked but used gets(). I tried replacing the gets... but the program no longer works. Here is the code, i was hoping someone could find the error (usi...