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
3
votes
2 answers

Prefix function as a predicate for filter function

Here is the type signature and the definition of the filter function from Learn You a Haskell for Great Good!: filter' :: (a -> Bool) -> [a] -> [a] filter' _ [] = [] filter' p (x:xs) | p x = x : filter' p xs | otherwise = filter' p xs An…
Ghost Bunnies
  • 177
  • 1
  • 1
  • 8
3
votes
1 answer

Right associative operator in a mathematical expression parser

Finally, coming from this question, the problem remains, that this subparser... private static void Factor(Scanner scanner, ref TermNode currentTree, ref Token currentToken) { Exponent(scanner, ref currentTree, ref currentToken); while…
HerpDerpington
  • 3,751
  • 4
  • 27
  • 43
3
votes
2 answers

Scala: How can I create a function that allows me to use dot notation when calling it?

I have been confused about this for a while, even despite reading the Scala Style Guide - Method Invocation several times. I want to be able to call this method def foldRVL[A,B](l: List[A], z: B)(f: (A, B) => B) = //"Right-Via-Left" …
Nicholas Montaño
  • 935
  • 10
  • 24
3
votes
2 answers

Scala - defining own infix operators

Methods taking a single argument can be written as an infix operators in Scal. I.e. adding *(other:C) = foo(this, other) to class C, will allow us to write c1 * c2 instead of foo(c1,c2). But is there a way to define infix operators on existing…
User1291
  • 7,664
  • 8
  • 51
  • 108
3
votes
2 answers

Convert Infix to Postfix with Stack

I have to make a program that changes an expression written in Infix notation to Postfix notation. I am running into a problem when I start using parentheses. For example, when I put in "a + (c - h) / (b * d)" is comes out as "ac+h-b/d*" when it…
Joe
  • 61
  • 2
  • 3
  • 8
3
votes
1 answer

Infix to postfix conversion in Python

I have started solving Data Structure problems in Python. I am implementing infix to postfix but not able to debug an error in my program. The final return statement where I perform join operation has input of type NONE. When I started debugging, I…
mrsan22
  • 727
  • 2
  • 11
  • 28
3
votes
3 answers

Infix to Postfix

I am trying to convert infix to postfix.For example : "20 + 2 * 3 + (2*8 + 5)* 4" ->20 2 3 * + 2 8 * 5 + 4 * + here is my code : Stack s = new Stack(); String postfix = ""; boolean enter = true; String…
3
votes
2 answers

Syntax error with "infixl" and "infixr" operators

I want to update a record using lens with a value parsed by attoparsec. fmap (myRecord & _2 . someField .~) double And it totally doesn't work: Iddq3.hs:99:48: The operator ‘.~’ [infixr 4] of a section must have lower precedence than…
Michael Fox
  • 3,632
  • 1
  • 17
  • 27
3
votes
1 answer

Reassociating trees in Template Haskell AST's

I'm upgrading a library where I translate Haskell to another language. Right now I'm using Meta.Parse to read in a Haskell module, and get back its TemplateHaskell AST, as described here. The problem I'm running into is that, when I run the parse, I…
jmite
  • 8,171
  • 6
  • 40
  • 81
3
votes
1 answer

Declaring special (infix) functions in R packages

I am writing a package containing a function such as: "%IN%" <- function(x, table) x & match(x, table, nomatch = 0) > 0 When I Build & Reload the package (I use RStudio), this function is not available, as opposed to all other functions defined in…
Dominic Comtois
  • 10,230
  • 1
  • 39
  • 61
3
votes
1 answer

Using Script Engine Manager in Android to evaluate infix expressions

I want to implement the following code in Android. How do I do that? System.out.println("Enter a String"); Scanner sc = new Scanner(System.in); String string = sc.next(); System.out.println(new…
user2475511
  • 79
  • 1
  • 7
3
votes
1 answer

NullPointerException infix to postfix java using stack

Currently I am working on a project using an ArrayStack to change an infix to postfix and evaluating the postfix evaluation. For the first operator that appears when the program reads it, it sends back java.lang.NullPointerException at…
3
votes
3 answers

infix to postfix conversion for exponentiation operation

I am learning polish notation and i tried a program for infix to postfix conversion. My program executed in a fine manner for operators like + and - . But for exponentiation operation which is right associative its not working correctly. For eg: …
poorvank
  • 7,524
  • 19
  • 60
  • 102
3
votes
1 answer

Rewrite a monad computation in prefix notation

I'm trying to figure out how to rewrite a monadic computation with prefix notation (not for real practical goals, just for research), but the problem that one lambda doesn't see another one's parameter so given a working example *Main> [1, 3, 4]…
Maksee
  • 2,311
  • 2
  • 24
  • 34
3
votes
3 answers

How do I define infix functions in Haskell?

I'd like to define a function as infix, so that users don't have to manually surround the function with backticks to call it. Specifically, I'm writing a DSL-like function that accepts a Rank and Suit and contructs a Poker card record: --…
mcandre
  • 22,868
  • 20
  • 88
  • 147