Discussion:
Unary Operator Question
(too old to reply)
Rahul
2004-06-30 04:02:10 UTC
Permalink
Is such an expression allowed??

if (a*!b+c) then

endif;

Since we are not doing any type checking, this is a valid boolean expression
.Thus, as long as ! is followed by a valid identifier, boolean (true/false)
or function call should it be picked up? Similarly with Unary Minus :

if(a*-b+c) then

endif;

Is this allowed as well? Is this a symantic or a syntactical error and in
this assignment are we supposed to pick it up or not? Thank You.

Rahul Jagtiani
Nguyen Nguyen
2004-06-30 15:49:43 UTC
Permalink
Look at Troy's post from yesterday regarding expressions, "... you
do not need to differentiate between boolean expressions and arithmetic
expressions..."

Nguyen
Post by Rahul
Is such an expression allowed??
if (a*!b+c) then
endif;
Since we are not doing any type checking, this is a valid boolean expression
.Thus, as long as ! is followed by a valid identifier, boolean (true/false)
if(a*-b+c) then
endif;
Is this allowed as well? Is this a symantic or a syntactical error and in
this assignment are we supposed to pick it up or not? Thank You.
Rahul Jagtiani
RS Jagtiani
2004-06-30 16:40:48 UTC
Permalink
My question was actually for the unary operators. In the example's given,
should we accept or reject such expressions? i.e.

if (a*!b+c) then

endif;

Thank you.

Rahul Jagtiani
Post by Nguyen Nguyen
Look at Troy's post from yesterday regarding expressions, "... you
do not need to differentiate between boolean expressions and arithmetic
expressions..."
Nguyen
Post by Rahul
Is such an expression allowed??
if (a*!b+c) then
endif;
Since we are not doing any type checking, this is a valid boolean expression
.Thus, as long as ! is followed by a valid identifier, boolean (true/false)
if(a*-b+c) then
endif;
Is this allowed as well? Is this a symantic or a syntactical error and in
this assignment are we supposed to pick it up or not? Thank You.
Rahul Jagtiani
Nguyen Nguyen
2004-06-30 19:45:05 UTC
Permalink
Troy's post covers your example. A unary operator in front of
an expression is still an expression. You do not have to
differentiate between arithmetic and boolean expressions, so your
example (and many others) does not need to be detected in this assignment.

There is nothing wrong with the expression in your original question:
(a*-b+c). If a, b and c are all of the same type, this is a perfectly
valid arithmetic expression.

Nguyen
Post by RS Jagtiani
My question was actually for the unary operators. In the example's given,
should we accept or reject such expressions? i.e.
if (a*!b+c) then
endif;
Thank you.
Rahul Jagtiani
Post by Nguyen Nguyen
Look at Troy's post from yesterday regarding expressions, "... you
do not need to differentiate between boolean expressions and arithmetic
expressions..."
Nguyen
Post by Rahul
Is such an expression allowed??
if (a*!b+c) then
endif;
Since we are not doing any type checking, this is a valid boolean expression
.Thus, as long as ! is followed by a valid identifier, boolean (true/false)
if(a*-b+c) then
endif;
Is this allowed as well? Is this a symantic or a syntactical error and in
this assignment are we supposed to pick it up or not? Thank You.
Rahul Jagtiani
Nguyen Nguyen
2004-06-30 19:51:10 UTC
Permalink
Clarification:
a, b and c must be of the same type _and be integers_ for a*-b+c to be a
valid arithmetic expression. Type checking will be done during semantic
analysis.
Post by Nguyen Nguyen
Troy's post covers your example. A unary operator in front of
an expression is still an expression. You do not have to
differentiate between arithmetic and boolean expressions, so your
example (and many others) does not need to be detected in this assignment.
(a*-b+c). If a, b and c are all of the same type, this is a perfectly
valid arithmetic expression.
Nguyen
Post by RS Jagtiani
My question was actually for the unary operators. In the example's given,
should we accept or reject such expressions? i.e.
if (a*!b+c) then
endif;
Thank you.
Rahul Jagtiani
Post by Nguyen Nguyen
Look at Troy's post from yesterday regarding expressions, "... you
do not need to differentiate between boolean expressions and arithmetic
expressions..."
Nguyen
Post by Rahul
Is such an expression allowed??
if (a*!b+c) then
endif;
Since we are not doing any type checking, this is a valid boolean expression
.Thus, as long as ! is followed by a valid identifier, boolean (true/false)
if(a*-b+c) then
endif;
Is this allowed as well? Is this a symantic or a syntactical error and in
this assignment are we supposed to pick it up or not? Thank You.
Rahul Jagtiani
RS Jagtiani
2004-06-30 21:48:18 UTC
Permalink
Thank you for the reply. Now i have another question,

is this valid??

a <- !!!!!!!!!!!!!a ?

This allows the value of a to be "not"ed many times. Similarly:

a <- ------------a ?

Thank you.

Rahul Jagtiani
Post by Nguyen Nguyen
a, b and c must be of the same type _and be integers_ for a*-b+c to be a
valid arithmetic expression. Type checking will be done during semantic
analysis.
Post by Nguyen Nguyen
Troy's post covers your example. A unary operator in front of
an expression is still an expression. You do not have to
differentiate between arithmetic and boolean expressions, so your
example (and many others) does not need to be detected in this assignment.
(a*-b+c). If a, b and c are all of the same type, this is a perfectly
valid arithmetic expression.
Nguyen
Post by RS Jagtiani
My question was actually for the unary operators. In the example's given,
should we accept or reject such expressions? i.e.
if (a*!b+c) then
endif;
Thank you.
Rahul Jagtiani
Post by Nguyen Nguyen
Look at Troy's post from yesterday regarding expressions, "... you
do not need to differentiate between boolean expressions and arithmetic
expressions..."
Nguyen
Post by Rahul
Is such an expression allowed??
if (a*!b+c) then
endif;
Since we are not doing any type checking, this is a valid boolean expression
.Thus, as long as ! is followed by a valid identifier, boolean (true/false)
if(a*-b+c) then
endif;
Is this allowed as well? Is this a symantic or a syntactical error and in
this assignment are we supposed to pick it up or not? Thank You.
Rahul Jagtiani
Nguyen Nguyen
2004-07-01 21:19:51 UTC
Permalink
Both are valid.

Nguyen
Post by RS Jagtiani
Thank you for the reply. Now i have another question,
is this valid??
a <- !!!!!!!!!!!!!a ?
a <- ------------a ?
Thank you.
Rahul Jagtiani
Post by Nguyen Nguyen
a, b and c must be of the same type _and be integers_ for a*-b+c to be a
valid arithmetic expression. Type checking will be done during semantic
analysis.
Post by Nguyen Nguyen
Troy's post covers your example. A unary operator in front of
an expression is still an expression. You do not have to
differentiate between arithmetic and boolean expressions, so your
example (and many others) does not need to be detected in this assignment.
(a*-b+c). If a, b and c are all of the same type, this is a perfectly
valid arithmetic expression.
Nguyen
Post by RS Jagtiani
My question was actually for the unary operators. In the example's given,
should we accept or reject such expressions? i.e.
if (a*!b+c) then
endif;
Thank you.
Rahul Jagtiani
Post by Nguyen Nguyen
Look at Troy's post from yesterday regarding expressions, "... you
do not need to differentiate between boolean expressions and arithmetic
expressions..."
Nguyen
Post by Rahul
Is such an expression allowed??
if (a*!b+c) then
endif;
Since we are not doing any type checking, this is a valid boolean expression
.Thus, as long as ! is followed by a valid identifier, boolean (true/false)
if(a*-b+c) then
endif;
Is this allowed as well? Is this a symantic or a syntactical error and in
this assignment are we supposed to pick it up or not? Thank You.
Rahul Jagtiani
Loading...