From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ace3fca092a457cd X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!x40g2000prg.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Unary operator after binary operator: legal or not? Date: Mon, 30 Jul 2007 17:22:11 -0700 Organization: http://groups.google.com Message-ID: <1185841331.637593.83960@x40g2000prg.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1185841332 5557 127.0.0.1 (31 Jul 2007 00:22:12 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 31 Jul 2007 00:22:12 +0000 (UTC) In-Reply-To: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: x40g2000prg.googlegroups.com; posting-host=66.126.103.122; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news2.google.com comp.lang.ada:1283 Date: 2007-07-30T17:22:11-07:00 List-Id: On Jul 30, 3:52 pm, "Jeffrey R. Carter" wrote: > Here's something confusing I encountered: > > with Ada.Strings.Unbounded; > > function Xyz (Left, Right : in Ada.Strings.Unbounded.Unbounded_String) > return String is > function "+" (Right : in Ada.Strings.Unbounded.Unbounded_String) > return String renames Ada.Strings.Unbounded.To_String; > begin -- Xyz > if +Left <= +Right then > return +Left & +Right; > -- ^ Error reported here. > end if; > end Xyz; > > A compiler reports "missing operand", referencing the space after the "&". > > Why then does it accept the comparison in the previous line? Both are > > +Left [binary operator] +Right I think that was a deliberate decision. See the BNF in 4.4. The operands of "and", "and then", "or", "or else", "xor", "in", or relational operators are . The definition of a is [unary_adding_operator] term {binary_adding_operator term} A unary_adding_operator is part of the syntax of but not of , so the consequences is that the right operator of a binary_adding_operator (or a multiplying_operator, or "**" or "abs" or "not") can't start with a unary adding operator, unless you parenthesize it. But the right operand of a relational operator or one of the logical operators I listed above *can* start with a unary adding operator. -- Adam