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
7
votes
1 answer

Why is exporting fixity declarations a "bad idea"?

According to David MacQueen in his Reflections on Standard ML report1, Lexically-scoped infix directives were an ill-advised legacy from Pop-2. They complicate parsing and they do not work well with the module system because infix directives cannot…
Moth
  • 253
  • 2
  • 8
7
votes
1 answer

How to convert from infix to postfix/prefix using AST python module?

I'm trying to convert python math expressions to postfix notation using the AST python module. Here's what I got so far: import parser import ast from math import sin, cos, tan formulas = [ "1+2", "1+2*3", "1/2", "(1+2)*3", …
BPL
  • 9,632
  • 9
  • 59
  • 117
7
votes
1 answer

Can we use infix generic methods in Kotlin ?

Compiler accept infix+generic methods, but what is the syntax to use it ? Example, given those 2 identical methods (modulo arbitrary generic type) : infix inline fun Int1.plus1(i: Int1) = Int1(this.value + i.value) infix inline fun Int1.plus2(i:…
Jeremy L
  • 251
  • 1
  • 3
  • 12
7
votes
1 answer

`flip` arguments of infix application inline

Given a function for infix usage: let f a b = (a+10, b) f 4 5 => (14,5) 4 `f` 5 => (14,5) The arguments can be flipped by defining a helper function: let g = flip f 4 `g` 5 => (15,4) Is it possible to do this inline? 4 `flip f` 5 => parse error on…
Tobias Hermann
  • 9,936
  • 6
  • 61
  • 134
7
votes
3 answers

Common lisp: is there a less painful way to input math expressions?

I enjoy common lisp, but sometimes it is really painful to input simple math expressions like a(8b^2+1)+4bc(4b^2+1) (Sure I can convert this, but it is kind of slow, I write (+ () ()) first, and then in each bracket I put (* () ())...) I'm…
h__
  • 865
  • 1
  • 11
  • 19
6
votes
2 answers

Scheme: Lists of three dotted elements returning strangely (like an infix operator?)

I am a new Scheme/Racket student, so please excuse any blatant syntax errors. It came up in class today that the scheme list '(a, b, c) should be invalid, but when we ran it, it returned: >'(a . b . c) (b a c) Which makes no sense. Afaik, the…
Erty Seidohl
  • 4,487
  • 3
  • 33
  • 45
6
votes
4 answers

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…
sanity
  • 35,347
  • 40
  • 135
  • 226
6
votes
1 answer

Converting LaTeX expression to infix expression

Let us assume we have an expression in LaTeX form: var latex =\frac{x}{\frac{y}{y}} So output required is: output= (x)/((y)/(y)); I tried out an example as stated in the link: Convert LaTeX to dynamic Javascript function but I am getting the…
VizardCrawler
  • 1,343
  • 10
  • 16
6
votes
2 answers

Scala DSL, Object and infix notation

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…
Felix
  • 8,385
  • 10
  • 40
  • 59
6
votes
1 answer

Arithmetic Expression Evaluation using Reverse Polish Notation (RPN)

A mathematical expression is usually expressed in infix notation. For evaluation purposes, we can change it to postfix (reverse polish) notation (using algorithms like Shunting-Yard) and then evaluate the postfix notation using stack. I found out…
6
votes
1 answer

Handling extra operators in Shunting-yard

Given an input like this: 3+4+ Algorithm turns it in to 3 4 + + I can find the error when it's time to execute the postfix expression. But, is it possible to spot this during the conversion? (Wikipedia article and internet articles I've read do not…
mikbal
  • 1,168
  • 1
  • 16
  • 27
5
votes
2 answers

Syntax for partial application of curried functions with reverse-associative infix notation

In other words, is there a good reason why this shouldn't compile? def f(xs: List[Int]) = xs.foldLeft(0) _ // OK def f(xs: List[Int]) = (xs :\ 0) _ // OK def f(xs: List[Int]) = (0 /: xs) _ :15: error: missing arguments for method /:…
Luigi Plinge
  • 50,650
  • 20
  • 113
  • 180
5
votes
1 answer

android - kotlin infix not working on one parameter extension function

take a look at this simple extension function i have infix: infix fun View.isValidColor(hexColor: String?): Boolean { var isValid = true return hexColor?.let { try { Color.parseColor(it) } catch (e: Throwable) { …
j2emanue
  • 60,549
  • 65
  • 286
  • 456
5
votes
1 answer

Infix to postfix for negative numbers

How do I convert negative numbers from infix to postfix ? Suppose I have a expression a = - b - (-c-d) In some places I read that you can parathesize the negative numbers like a = (-b) - (-c-d) But here if I do that, I will get a term like "ab-"…
Zephyr
  • 1,521
  • 3
  • 22
  • 42
5
votes
2 answers

python infix forward pipe

I'm trying to implement a forward pipe functionality, like bash's | or R's recent %>%. I've seen this implementation https://mdk.fr/blog/pipe-infix-syntax-for-python.html, but this requires that we define in advance all the functions that might work…
keegan
  • 2,892
  • 1
  • 17
  • 20
1 2
3
35 36