Path: ...!feeds.phibee-telecom.net!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Bart Newsgroups: comp.lang.c Subject: Re: how to make a macro work as a single line if stmt without braces Date: Tue, 24 Sep 2024 21:12:28 +0100 Organization: A noiseless patient Spider Lines: 45 Message-ID: References: <20240922080605.59@kylheku.com> <20240922192726.000061fc@yahoo.com> <86ikul6ruw.fsf@linuxsc.com> <20240924125421.1@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 24 Sep 2024 22:12:27 +0200 (CEST) Injection-Info: dont-email.me; posting-host="95ee115af698825001a4f77256ea5076"; logging-data="3498691"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19CI4bT+IS+c+7Eu3dYJLLa" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:OoT7z3NdLrv0Fumx5kQd9hrF94Y= Content-Language: en-GB In-Reply-To: <20240924125421.1@kylheku.com> Bytes: 2746 On 24/09/2024 20:59, Kaz Kylheku wrote: > On 2024-09-24, Bart wrote: >> (Maybe the language needs a construct like 'elif', as is used in > > The language doesn't need such a construct in order for a compiler > to implement it internally. > > You just have to treat the token sequence else if as a supertoken. > > Doing it at the grammar level may require two symbols of lookahead, > which is a a problem for off-the-shelf parser generation tooling based > on LALR(1) and whatnot. That sounds as much of a hack as making a special case for 'else if' so that it doesn't need 'else {if' (and a matching } later on) when enforcing compound statements for such blocks. One consequence of how it works now is that if I write: if (a) {} else if (b) {} else if (c) {} else {} then use a tool I have to visualise C code in my syntax, it generates: if a then else if b then else if c then else fi fi fi The nested nature is revealed. If there were 50 'else if' links, the output would disappear off to the right. With elif, elsif etc, the compiler has the option to keep the internal structure linear (which also means it will not put pressure on the stack if somebody decides to write a million of them).