# right to left vs unary op

## right to left vs unary op

Deep in another thread you stated in lack of parenthesis assume right to left evaluation

a = -1 + 2 + 3;

Right to left evaluation is equivalent to -(1 + (2 + 3)) = -6
as opposed to (-1) + (2 + 3) = 4

then there is

a = 1 + -2 + 3; ? -4 or 2 ?

IMHO unary operators +and - have to be specified (presumably with higher precedence than arithmetic operators)

Jim Dempsey

www.quickthreadprogramming.com
13 帖子 / 0 new

I think they actually meant Left to Right evaluation (right to left is just too weird) G

I believe unary operators have been disallowed. See here

Quoting akki I believe unary operators have been disallowed. See here

I think the same, but many participants include it to their grammars through and through.

Quoting dweeberlyloom I think they actually meant Left to Right evaluation (right to left is just too weird) G

What you are assuming they meant and what they (Rama) say seem to be at odds with one another.

Rama stated "Please evaluate expressions from right to left in the RHS of the mathematical expression."

http://software.intel.com/en-us/forums/showpost.php?p=152354

Jim Dempsey

www.quickthreadprogramming.com
Quoting akki I believe unary operators have been disallowed. See here

So it seems we cannot use

var m1 = -1;

and must resort to something like

var m1 = 0 - 1;

I am not objecting to this requirement (or shortcomming). I am objecting to not addressing this in the rules.

The rules could have stated:

No unary operators are supported. To enter in a negative number use an expression without an unary operator.
Example:
var x = 0-1;

Jim Dempsey

www.quickthreadprogramming.com

The rules I learned from other threads; they are kind of the rules of rules which cover all the rule instances we asked

When I use a word," Humpty Dumpty said in rather a scornful tone, "it means just what I choose it to mean - neither more nor less.

www.quickthreadprogramming.com

Although general negation via a unary op isn't supported, it would make sense that negative values are, so that integral and floating point literals can have an optional + or - in front of the number, with no space in between.

Quoting mdma Although general negation via a unary op isn't supported, it would make sense that negative values are, so that integral and floating point literals can have an optional + or - in front of the number, with no space in between.

So then they are supported, at least as a first character in expression. This would mean -(a+b)would be supported too. As far as I can determine from disscussions on this forum, from Intel employees which I assume are on the rules committee, unary operators are not supported.

If the rules committee wants to say"unary operators not covered in the rules". Then it would be fair for them to also say "None of the test files will contain unary operators. Not even as a test for error in syntax." _and_ to also assert that none exist in their test data. If they do this then anyone can choose to implement or not implement unary operators without risking points.

Jim Dempsey

www.quickthreadprogramming.com

Unary operators are not supported - and I'm not saying otherwise - let's be clear about that. My point was that even though unary operators are disallowed, the minus sign in front of a literal doesn't have to be a unary operator, but part of the literal definition. In the same way C allows L and d to be appended, or 0x to be prepended to a literal - these are not operators but part of the literal definition. Whether negative literals are allowed, and any ensuing complexities this brings (such as ambiguity if spaces are not significant) is of course a matter for the judges to decide.

Quoting mdma Unary operators are not supported - and I'm not saying otherwise - let's be clear about that. My point was that even though unary operators are disallowed, the minus sign in front of a literal doesn't have to be a unary operator, but part of the literal definition. In the same way C allows L and d to be appended, or 0x to be prepended to a literal - these are not operators but part of the literal definition. Whether negative literals are allowed, and any ensuing complexities this brings (such as ambiguity if spaces are not significant) is of course a matter for the judges to decide.

What I'd like to be able to say is that we support at least negative numeric constants, and if that naturally results in the support of unary negation, no big deal so long as the inputs won't actually test for error or correctness of more general unary negation.

@MDMA: I think that you are recommending something contrary to how languages are built. For example check out the "C" syntax (samples here): http://www.csci.csusb.edu/dick/samples/c.syntax.html http://www.externsoft.ch/download/cpp-iso.html Languages don't include '-' as part of the numeric literal because it is nearly impossible to process correctly, since the lexer is upstream of the parser and has no idea about its syntax. Consider: var x = -1-2; If the "negative sign is part of number" rule is followed, this will produce tokens: VAR IDENTIFIER EQUAL NUMBER NUMBER SEMICOLON Which does NOT match any rule -- the middle '-' was absorbed into the second NUMBER. On the other hand, if the '-' is not part of the number, you get VAR IDENTIFIER EQUAL MINUS NUMBER MINUSNUMBER SEMICOLON The easiest way to parse this is to simply say that you support unary negation expressions, although you could write a special case for constants instead.

var x = -1-2;

Left to right evaluation (-1)-2;
Right to left evaluation -(1-2); (unless unary op and unary op has precidence)

Rama stated right to left evaluation (with possibility for ()'s) and no unary support;

We will have to assume first non-blank character of numeric value or preceeding variable is never -.

Jim

www.quickthreadprogramming.com