From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 45295 invoked by alias); 16 Jul 2015 14:51:54 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 45282 invoked by uid 89); 16 Jul 2015 14:51:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx2.suse.de Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Thu, 16 Jul 2015 14:51:52 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id AC109AB08 for ; Thu, 16 Jul 2015 14:51:49 +0000 (UTC) Date: Thu, 16 Jul 2015 15:00:00 -0000 From: Michael Matz To: Richard Biener cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Add 'switch' statement to match.pd language In-Reply-To: Message-ID: References: <9742E78F-EF7F-4AFB-8F26-D3B5871BA366@gmail.com> User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-IsSubscribed: yes X-SW-Source: 2015-07/txt/msg01414.txt.bz2 Hi, On Thu, 16 Jul 2015, Richard Biener wrote: > > Similar, if the condition is an atom you should be able to leave the > > parens away: > > > > (switch > > cond (minus @0 @1) > > ) > > > > (given a predicate 'cond' defined appropriately). > > Yes. Though techincally the condition cannot be an atom because > it has to be a c-expr and that has no notion of atom vs. no-atom. "1" is a valid c-expr, and quite atomy :) (Or "true") > But the issue is to unambiguously parse the else clause, thus Ah, yes, I remember, the c-expr vs expr case; the parser is too limited :) In that case I find the extra keyword without parens even better: (switch when (bla) (foo) when (bar) (boo) (blob)) I.e. following 'when' it's an c-expr (when single token, parens optional), when not following 'when' its a result expr (atomic or not). Think of it as an infix multi-part keyword (like smalltalk has multi-part method names), the keyword(s) being "switch(when)*". I'm undecided if I'd allow function calls as atoms as well (because they contain parens), like so: (switch when integer_zero(@0) @1 when integer_zero(@1) @0 (plus @0 @1)) This would mean that there would be no single-token conditions without parens where one could leave out outer parens, as otherwise you have a ambiguity between: (switch when true (@0) // (@0) is the result ...) and (switch when token(@0) @1 // (@0) belongs to the when-expr ...) One has to chose between one or the other, and I think the latter (i.e. function calls as lone when-expr) occur more often. (Limiting the number of parens is worthwhile IMHO, but you probably guessed that much already :)) Ciao, Michael.