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
76
votes
43 answers

Evaluating a string of simple 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…
Noldorin
  • 144,213
  • 56
  • 264
  • 302
52
votes
5 answers

How to evaluate an infix expression in just one scan using stacks?

I want to know if there is a way to solve infix expressions in a single pass using 2 stacks? The stacks can be one for operator and the other for operands... The standard way to solve by shunt-yard algorithm is to convert the infix expression to…
nikoo28
  • 2,961
  • 1
  • 29
  • 39
41
votes
4 answers

Scala - infix vs dot notation

Is there a best practice for one over the other? I've been reading the Scala book by Odersky, et al. and it seems like infix is used for a lot of the Collections API functions, whereas dot is reserved for programmer-defined functions.
Kevin Li
  • 1,540
  • 2
  • 17
  • 23
38
votes
1 answer

How to make a right-associative infix operator?

I have an associative operation >>. The problem is that its cost linearly depends on the size of its left operand. So an expression formed by a sequence of n applications of >> like a >> a >> a >> a >> a >> ... >> a it has quadratic cost in terms…
Petr
  • 62,528
  • 13
  • 153
  • 317
35
votes
7 answers

"Piping" output from one function to another using Python infix syntax

I'm trying to replicate, roughly, the dplyr package from R using Python/Pandas (as a learning exercise). Something I'm stuck on is the "piping" functionality. In R/dplyr, this is done using the pipe-operator %>%, where x %>% f(y) is equivalent to…
Malthus
  • 568
  • 1
  • 7
  • 11
31
votes
2 answers

Haskell infix function application precedence

Let f x y = x * y. We can apply this function in two ways: f 5 6, or, using infix notation, 5 `f` 6. Do the operator rules apply to this last expression? What precedence will this application have? Is it just another form of function application,…
demi
  • 5,384
  • 6
  • 37
  • 57
28
votes
2 answers

How does the 'infix' work?

I'm playing with the infixr, infixl and infix declarations. I understand how infixr and infixl works: -- Test expression: 40 +++ 20 +++ 50 +++ 10 * 10 -- infixr 8 +++ -- Calculated as: (40 +++ (20 +++ (50 +++ 10))) * 10. Result: 630. -- infixl 8…
Andrey Bushman
  • 11,712
  • 17
  • 87
  • 182
26
votes
9 answers

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…
adam shankman
  • 261
  • 1
  • 3
  • 3
23
votes
2 answers

Implementation of a function object "power" operator in Raku

In APL there is the power operator ⍣, which if applied to a function f superimposes the application of f. How to implement that operator in Raku? For example, with this definition of f: sub f(Int:D $i){ $i + 1 } the command say (f ⍣ 4)(10); should…
Anton Antonov
  • 726
  • 4
  • 11
21
votes
2 answers

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

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…
ciuncan
  • 1,062
  • 2
  • 11
  • 25
19
votes
2 answers

What does ':..' mean in Haskell?

I'm reading a following datatype: data Ne = NVar Id | Ne :.. (Clos Term) | NSplit Ne (Bind (Bind (Clos Term))) | NCase Ne (Clos [(Label, Term)]) | NForce Ne | NUnfold Ne (Bind (Clos Term)) deriving (Show, Eq) What is :.. in the second…
19
votes
2 answers

Cannot declare an operator within a function. Clang bug or spec?

One of the weirder corner cases of C is that functions can be declared within other functions, e.g. void foo(void) { void bar(void); // Behaves as if this was written above void foo(void) bar(); } This has carried through into C++, at least for…
Jon Chesterfield
  • 2,251
  • 1
  • 20
  • 30
16
votes
4 answers

When to use parenthesis in Scala infix notation

When programming in Scala, I do more and more functional stuff. However, when using infix notation it is hard to tell when you need parenthesis and when you don't. For example the following piece of code: def caesar(k:Int)(c:Char) = c match { …
Felix
  • 8,385
  • 10
  • 40
  • 59
16
votes
6 answers

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…
Biswajyoti Das
  • 7,881
  • 11
  • 34
  • 26
15
votes
2 answers

How to define an infix (not symbolic aka not an operator) function in OCaml?

does OCaml support infix functions defined in plaintext ? arg1 `plus` arg2 = arg1 + arg2 thanks
desmogix
  • 217
  • 2
  • 8
1
2 3
35 36