From:  Kaz Kylheku <643-408-1753@kylheku.com>
Date:  25 Sep 2024 03:59:30 Hong Kong Time
Newsgroup:  news.alt119.net/comp.lang.c
Subject:  

Re: how to make a macro work as a single line if stmt without braces

NNTP-Posting-Host:  null

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.

A possible trick is to handle it at the lexical level. The pattern
else{WSP}if can be recognized as a single token, assigned its own
enumeration symbol. {WSP} is arbitrary whitespace. (We assume
comments have been stripped by a lower preprocessing phase.)

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca