From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3433 invoked by alias); 6 Mar 2015 16:10:45 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19977 Received: (qmail 23632 invoked from network); 6 Mar 2015 16:10:43 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-Authority-Analysis: v=2.1 cv=X+5rdgje c=1 sm=1 tr=0 a=7K8QI4x6DXfJejJdwhsEbQ==:117 a=7K8QI4x6DXfJejJdwhsEbQ==:17 a=VNsaWKQvMhEA:10 a=N659UExz7-8A:10 a=eUE45k6NNeuT-EaQtlMA:9 a=pILNOxqGKmIA:10 Message-id: <54F9D180.4020900@eastlink.ca> Date: Fri, 06 Mar 2015 08:10:40 -0800 From: Ray Andrews User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.4.0 MIME-version: 1.0 To: zsh-users@zsh.org Subject: Re: grammar triviality with '&&' References: <54F33934.2070607@eastlink.ca> <13666281425228233@web7o.yandex.ru> <54F345D3.9010204@eastlink.ca> <20150302022754.GA7449@xvii.vinc17.org> <150302005440.ZM16546@torch.brasslantern.com> <20150302103156.GB6869@xvii.vinc17.org> <150302084958.ZM17306@torch.brasslantern.com> <20150304085512.GA3609@ypig.lip.ens-lyon.fr> <54F73D18.8070801@eastlink.ca> <150305205951.ZM8811@torch.brasslantern.com> In-reply-to: <150305205951.ZM8811@torch.brasslantern.com> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit On 03/05/2015 08:59 PM, Bart Schaefer wrote: > On Mar 4, 9:12am, Ray Andrews wrote: > } > } If an extra degree of freedom and capability was possible, and IF it > } could be implemented with no gotchas, then why not? > > Because we don't need the grammar to become any more ad-hoc than it > already has? A quite sufficient reason. My very unlearned sense of it was that the errorlevel test is implicit in any '&&' anyway, and since that test wraps 'down' legally already, then it would be trivially simple to understand that that same value is grabbed when '&&' starts a line. I was liking Vincent's thinking. Or not! It seemed to me like a relaxation of something arbitrary. However if it really would be add-hoc then of course it can't be touched. Please recall that this is a *question*. > > Back in the depths of time, one of the reasons zsh was invented was > because csh's grammar was too irregular. Csh scripts originally (I > can't speak for how tcsh &c. may be now) could in fact be interpreted > one line at a time, and literally were: "while" loop was processed by > remembering the file position of the string "while" and then when the > "end" was encountered, seeking back and re-reading the lines again. > This made it possible to write some really entertaining scripts that > edited their own code on the fly, but made it impossible to syntax > check a multi-line control structure before beginning to execute it. God forbid. > > The Bourne-shell / POSIX shell grammar is at least regular enough to > be parsed before it is executed, even with all its other warts. > Introducing a case where the command to the left of && / || can be > empty if and only if the conjunction is the first token on a line, is > the kind of irregularity that should be avoided. > > Further, in the standard definition of the grammar where pipelines > separated by && or || form a sublist, the terminator that follows is > syntactically significant to the whole sublist. That is: > > one && two || three & > > is parsed as > > { one && two || three } & > > which is not the same as > > one ; [[ $? = 0 ]] && two ; [[ $? = 0 ]] || three & Well that kills my notion that it's implicit, I thought the latter was what was really going on in any case. Dare a mortal ask what the difference is between those? The deeper question is why shells were designed this way. In C this sort of obscurity not only doesn't exist, it couldn't exist, you can wrap code anyway you want (string printing excepted). But shells are written in C, yet the decision was made to make things so convoluted that no one fully understands them. This work was done by geniuses so there musta been a good reason.