What does it mean with infix

T

Tony Johansson

Hello Experts!

I'm reading i a book about C++ and they mention infix with telling what it
is.
I hope you out there can do so.

Many thanks!
//Tony
 
O

osmium

Tony Johansson said:
I'm reading i a book about C++ and they mention infix with telling what it
is.
I hope you out there can do so.

Infix means the operators are between the operands, just the ordinary way
you learned in school. There is also postfix and prefix which you may be
exposed to later..
 
V

Victor Bazarov

osmium said:
:




Infix means the operators are between the operands, just the ordinary way
you learned in school. There is also postfix and prefix which you may be
exposed to later..

Actually, isn't prefix notation used in C++ for function calls,
essentially? Name of the function comes first, then the list of
the arguments...

V
 
R

Rolf Magnus

Victor said:
^^^^^^^^^


Actually, isn't prefix notation used in C++ for function calls,
essentially?

Yes, but for binary operators usually not. Unary ones are prefix or postfix,
depending on the operator.
 
P

Pelle Beckman

Victor Bazarov skrev:
Actually, isn't prefix notation used in C++ for function calls,
essentially? Name of the function comes first, then the list of
the arguments...

V

I'd say it's the other way around - functions are called by
the ()-operator which is postfix.

On the other hand the ()-operator takes arguments inside it...

-- Pelle
 
V

Victor Bazarov

Pelle said:
[...]
I'd say it's the other way around - functions are called by
the ()-operator which is postfix.

On the other hand the ()-operator takes arguments inside it...

So, if it's not infix or postfix or prefix, what is it? Outfix?
 
E

E. Robert Tisdale

Pelle said:
Victor Bazarov skrev:
osmium said:
:

I'm reading i a book about C++
and they mention infix with[out] telling what it is.
I hope you out there can do so.

Infix means the operators are between the operands,
just the ordinary way you learned in school.
There is also postfix and prefix
which you may be exposed to later..


Actually, isn't prefix notation used in C++
for function calls, essentially?
Name of the function comes first,
then the list of the arguments...

I'd say it's the other way around -
functions are called by the ()-operator which is postfix.

You probably mean operator().

The function name itself is a prefix operator.
Consider

sin(x); // sin x
cos(x); // cos x

for example.

You might think of a function invocation
as the application of a postfix operator()
to a function name but the real reason is that,
unlike some other computer programming languages,
C++ does *not* recognize juxtaposition of two identifiers
as the application of an operator (function).
 
R

rossum

Hello Experts!

I'm reading i a book about C++ and they mention infix with telling what it
is.
I hope you out there can do so.

Many thanks!
//Tony

Infix, prefix and postfix are about the relative positioning of an
operator and its operand(s). For binary operators (two operands) this
looks like:

prefix: + 1 2

infix: 1 + 2

postfix: 1 2 + (sometimes called "reverse Polish notation")

HTH

rossum






The ultimate truth is that there is no ultimate truth
 
M

Mike Wahler

Victor Bazarov said:
Pelle said:
[...]
I'd say it's the other way around - functions are called by
the ()-operator which is postfix.

On the other hand the ()-operator takes arguments inside it...

So, if it's not infix or postfix or prefix, what is it? Outfix?

It's broken. Fix it. :)

-Mike
 
P

Pelle Beckman

rossum skrev:
Infix, prefix and postfix are about the relative positioning of an
operator and its operand(s). For binary operators (two operands) this
looks like:

prefix: + 1 2

infix: 1 + 2

postfix: 1 2 + (sometimes called "reverse Polish notation")

Whats "standard Polish notation" then? ordinary prefix ( + 1 2)?
 
A

Andre Caldas

prefix: + 1 2
Whats "standard Polish notation" then? ordinary prefix ( + 1 2)?

Sorry, I don't really know the "formal definition" of "Standard Polish
Notation". But I guess this is one example:

1 2 3 + 4 * +
1 + 4 * (2 + 3)

Andre Caldas.
 
M

msalters

Victor said:
Actually, isn't prefix notation used in C++ for function calls,
essentially? Name of the function comes first, then the list of
the arguments...

RTFS ;)
5.2
"A function call is a postfix expression", it's the third form in the
grammar given for postfix-expression's.
 
R

Rolf Magnus

Mike said:
Victor Bazarov said:
Pelle said:
[...]
I'd say it's the other way around - functions are called by
the ()-operator which is postfix.

On the other hand the ()-operator takes arguments inside it...

So, if it's not infix or postfix or prefix, what is it? Outfix?

It's broken. Fix it. :)

So we call a function now as:

function () parameter;

Then () becomes an infix operator.
 
R

Rolf Magnus

Andre said:
Sorry, I don't really know the "formal definition" of "Standard Polish
Notation". But I guess this is one example:

1 2 3 + 4 * +

That's postfix, i.e. RPN. It is used in some pocket calculators, like HP 48,
which I have. It's actually superior to the infix notation in this case,
but you have to get used to it.
1 + 4 * (2 + 3)

That'd be infix.

PN would be:

+ 1 * + 2 3 4
 
V

Victor Bazarov

Rolf said:
Mike Wahler wrote:

Pelle Beckman wrote:

[...]
I'd say it's the other way around - functions are called by
the ()-operator which is postfix.

On the other hand the ()-operator takes arguments inside it...

So, if it's not infix or postfix or prefix, what is it? Outfix?

It's broken. Fix it. :)


So we call a function now as:

function () parameter;

Then () becomes an infix operator.

Does that mean that for more than one argument we need to do

function () argument1 () argument2 () argument3

to be infix? Seems lame.

V
 
R

Rolf Magnus

Victor said:
Rolf said:
Mike Wahler wrote:

Pelle Beckman wrote:

[...]
I'd say it's the other way around - functions are called by
the ()-operator which is postfix.

On the other hand the ()-operator takes arguments inside it...

So, if it's not infix or postfix or prefix, what is it? Outfix?

It's broken. Fix it. :)


So we call a function now as:

function () parameter;

Then () becomes an infix operator.

Does that mean that for more than one argument we need to do

function () argument1 () argument2 () argument3

to be infix? Seems lame.


However, it doesn't look much different from how streaming is done in C++:

std::cout << "Hell" << "o world" << std::endl;

Is that lame, too? (Actually, IMHO, it is).
 
V

Victor Bazarov

Rolf said:
Victor Bazarov wrote:

Rolf said:
Mike Wahler wrote:





Pelle Beckman wrote:


[...]
I'd say it's the other way around - functions are called by
the ()-operator which is postfix.

On the other hand the ()-operator takes arguments inside it...

So, if it's not infix or postfix or prefix, what is it? Outfix?

It's broken. Fix it. :)


So we call a function now as:

function () parameter;

Then () becomes an infix operator.

Does that mean that for more than one argument we need to do

function () argument1 () argument2 () argument3

to be infix? Seems lame.



However, it doesn't look much different from how streaming is done in C++:

std::cout << "Hell" << "o world" << std::endl;

Is that lame, too? (Actually, IMHO, it is).

The bid difference here is that operator << takes only two arguments and
returns something that can be used as another left argument (operand) for
the next operator <<. The meaning of

func () arg1 () arg2 () arg3

is not "Call 'func' with 'arg1' then treat the return value as another
function which you call with 'arg2', etc." I would like it to mean "call
'func' with three arguments". Never mind...

V
 
A

Andre Caldas

1 2 3 + 4 * +
That's postfix, i.e. RPN. It is used in some pocket calculators, like HP 48,

I think that for you to have "postfix", or "wathever-fix", you need:
* One operator
* One or more operands
What are the operands for the last "+" in the expression?

This is just the same as:
push 1
push 2
add
push 4
multiply
add
which I have. It's actually superior to the infix notation in this case,

I don't know if it is "superior", but it is much easier to parse since
there are no recursions.

PN would be:
+ 1 * + 2 3 4

Sorry, I don't understand this :-(

Andre Caldas.
 
K

Karl Heinz Buchegger

Andre said:
I think that for you to have "postfix", or "wathever-fix", you need:
* One operator
* One or more operands
What are the operands for the last "+" in the expression?

Ther result of 2 3 + 4 *
and the 1

You obviously never had a HP pocket calculator :)

Consider the tree

+
/ \
1 *
/ \
+ 4
/ \
2 3

There are various ways to run through the tree:
preorder, inorder, postorder

preorder: the node first, then left subtree, right subtree
inorder: left subtree first, node, right subtree
postoder: left subtree first, right subtree, node

doing this for the above tree gives:

preorder: + 1 * + 2 3 4
inorder: 1 + 2 + 3 * 4
postorder: 1 2 3 + 4 * +

All 3 representations represent the same tree (same expression),
but only inorder requires some ( )

1 + ( ( 2 + 3 ) * 4 )

to guide you through the presedence during evaluation. The other 2 don't need that.
This is just the same as:
push 1
push 2
add
push 4
multiply
add

You forget one
push 3
I don't know if it is "superior", but it is much easier to parse since
there are no recursions.

Parsing is not the problem. Evaluating is!
With inorder notation, you need to incorporate the arithmetic rules
of precedence. It is not uncommon for compilers to first build
an expression tree from an infix notation, traverse that expression
tree in postorder and emit the code from that postorder traversel.
Why? Because arithmetic precedence has already been dealt with during
parsing and the tree has organized the opertions already correctly.
Sorry, I don't understand this :-(

+ add the next 2 expressions
1 the immediatly following expression equals 1
* + 2 3 4 thats the second expressions that gets added (since it starts with *
it is not a number, but an expression)
More exactly, it is the result of that expression that participates
in the add, so lets evaluate that

* multiply
+ 2 3 the result of that
4 with 4

Now we need to evaluate + 2 3

+ add
2 this
3 with that

in a more functional approach (as eg. in Lisp) the whole expression can be written
as:

add( 1, times( add( 2, 3 ), 4 ) )
 
A

Andre Caldas

postfix: 1 2 + (sometimes called "reverse Polish notation")
I missunderstood your comment/question. Sorry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top