Questions tagged [infix-notation]

Operators are written infix-style when they are placed between the operands they act on (e.g. 2 + 2).

Operators are written infix-style when they are placed between the operands they act on (e.g. 2 + 2).

There are a few ways to convert infix to postfix, AKA reverse polish notation.

When working with a recursive descent parser one can factor the grammar.

One can also implement the shunting yard algorithm by Edsger Dijkstra which can be refined into precedence climbing.

540 questions
4
votes
0 answers

Parameters with infix operator name?

In Haskell, we can use an infix operator as a parameter name, e.g.: f :: (Int -> Int -> Int) -> Int f (|+|) = 3 |+| 4 Is it possible to do something similar in Idris 2? I tried the following: f : (Int -> Int -> Int) -> Int f (|+|) = 3 |+| 4 But it…
Cactus
  • 27,075
  • 9
  • 69
  • 149
4
votes
4 answers

Prefix notation to infix notation in Python

I am writing a small calculator (with prefix notation) and I'm curious how I'd convert prefix notation to infix notation. I currently have a function, but it's being weird, and I'm not sure how to fix it. By being weird, I mean that if given ['+',…
tekknolagi
  • 10,663
  • 24
  • 75
  • 119
4
votes
2 answers

F# Common infix operators (fmap, applicative, bind, etc) for multiple types

What I would like do is use infix fmap (which I have defined as <^>) to work for multiple types such as Option and Either (custom type). Given: type Either<'a, 'b> = Left of 'a | Right of 'b In code I would like to be able to do: let fO (a :…
rbonallo
  • 970
  • 1
  • 9
  • 21
4
votes
2 answers

Infix notation and with(...) does not work as I expected

Consider the following scenario: I have a class Test class Test() { infix fun say(msg: String) = println(msg) } and a main method fun main(args: Array) { val test = Test() test say "Hello World!" //Works with(test) { …
Limnic
  • 1,826
  • 1
  • 20
  • 45
4
votes
1 answer

Trying to convert reverse polish notation to infix using an stack of strings, running into a small error and I don't know what's causing it

I've got a string stack implemented and I'm trying to convert rpn to infix using it. This is how the stack should look as the infix function works, for example if I entered 2 3 + 5 - 8 * : 2 //push 2 2,3 //push 3 (2+3) …
ccarlos999
  • 41
  • 3
4
votes
3 answers

Postfix to Infix with minimum number of parentheses

I am looking for algorithm postfix to infix notation which will produce the minimum number of the parentheses. I have found that but it will produce many, many parentheses:…
Yoda
  • 17,363
  • 67
  • 204
  • 344
4
votes
2 answers

Seg Fault at return statement in function

My program is supposed to convert a prompt from infix to postfix. So far, through a debugger and various other methods, I have located the exact point at which I segfault, but don't understand why. Here's my code: Here's itop.h: using namespace…
3
votes
3 answers

How do you use a function as an infix operator?

To use an infix operator as a prefix function in OCaml, you can put parenthesis around it. for example, 1 + 2 is equivalent to (+) 1 2. How do you do the opposite? For example, in Haskell, a prefix function taking two parameters can be used as an…
3
votes
2 answers

Sphinx search for exact match and then infix matches

I am using Sphinx to provide search to a website and I've run across a bit of a snag when returning relevant results. To keep my question simple, let's assume that I have two fields, @title and @body, which are weighted 100 & 15 respectively. When…
ServAce85
  • 1,602
  • 2
  • 23
  • 51
3
votes
1 answer

How do I parse infix instead of prefix with Haskell?

I need help with this program I am trying to write in Haskell. I have written most of it, and here is what I am basically trying to do: When I write parse "a + b" in the terminal I want this as output: Plus (Word "a") (Word "b") When I…
3
votes
2 answers

Does Solr Suggester support infix search?

The wiki page of the Solr Suggester component does not mention how the provided field is searched? Is it a prefix only, or is there also an infix search possible?
medihack
  • 16,045
  • 21
  • 90
  • 134
3
votes
2 answers

use a binary tree to encode infix arithmetic expressions on integers

This is a question from aws educate. I have been thinking about this for a long time and I am not really getting anywhere. You want to use a binary tree to encode infix arithmetic expressions on integers. Operations are addition and…
bsem
  • 175
  • 1
  • 2
  • 12
3
votes
1 answer

Converting a file to Swift 3: unable to infer closure type in the current context

I'm converting some library code in an app of mine, and I can't figure out how to convert this file from Swift 2.3 to Swift 3 import UIKit struct Constraint{ var identifier: String? var attribute: NSLayoutAttribute = .centerX var…
David
  • 7,028
  • 10
  • 48
  • 95
3
votes
2 answers

Infix to postfix conversion in java

I have a java class that converts infix expression to postfix. I have managed to make the class run without errors but it is not giving me the right output. The output is suppose to be in form : InToPost: converting expressions from infix to…
compcrk
  • 411
  • 4
  • 9
  • 18
3
votes
3 answers

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.…
Andrei
  • 10,918
  • 12
  • 76
  • 110