Article View: comp.lang.c
Article #425Re: Taming The Switch-Statement
From: bart
Date: Thu, 15 Oct 2026 14:57
Date: Thu, 15 Oct 2026 14:57
72 lines
3625 bytes
3625 bytes
On 15/10/2026 12:45, Dan Cross wrote:
> In article <11aqbqv$2avn3$1@dont-email.me>, bart <bc@freeuk.com> wrote:
>> Perhaps that reused keyword thing is a bigger deal than you think. The
>> effect of it is unnecessary obfuscation.
>
> This is certainly not evidence of that. This is just your
> assertion that you took a silly example and apparently (maybe?)
> improved it, based on some unstated, but apparently subjective,
> criteria.
I am stating that 'break' used to fix C's poor 'switch' feature
interferes with 'break' used for loops.
It's not even my opinion: it's fact. In your example, about a third of
'break' tokens are for taking care of switch.
My opinion is that it generates pointless clutter (this it would do even
if a different keyword was used), and it can get confusing when switch
and loop are mixed up.
I actually took your program and ported it to my syntax, as I was
curious how it would look. This is the result:
https://github.com/bart-2026/langs/blob/main/lexertest.m
(It's been spaced out more, vertically.)
There were some tricky bits of the C to translate, such as:
break;
default:
break;
}
default:
*tp++ = ch;
break;
}
}
*tp++ = '\0';
tt = TkSTRING;
where it seems to break from one switch then sneakily falls through into
the default clauses of the enclosing one!
Well, here are some stats:
C Mine
Size 3374 2997 characters (both with hard tabs)
Non-blank lines 210 174 Lines
I did try and run mine:
c:\mapps>test
1234
tok: tt = tkident, token = '1234'
abc
tok: tt = tkident, token = 'abc'
It shows both of these as an identifier. But yours does the same:
c:\c>a
1234
tok: tt = 1003, token = '1234'
abc
tok: tt = 1003, token = 'abc'
Whatever '1003' means, it's showing the same. So it will do (I don't
care if the code is buggy, just whether my version is reasonably faithful).
Of course, my actual lexers have a different structure.
Technical Details
Message-ID:
<11aqpl3$2gdup$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<119qf6l$2rmg3$1@dont-email.me> <11aoqa9$1rgda$1@dont-email.me> <11apa4b$kv$1@reader2.panix.com> <11aqbqv$2avn3$1@dont-email.me> <11aqect$hpr$1@reader2.panix.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: bart <bc@freeuk.com> Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Thu, 15 Oct 2026 15:57:38 +0100 Organization: A noiseless patient Spider Lines: 72 Message-ID: <11aqpl3$2gdup$1@dont-email.me> References: <119qf6l$2rmg3$1@dont-email.me> <11aoqa9$1rgda$1@dont-email.me> <11apa4b$kv$1@reader2.panix.com> <11aqbqv$2avn3$1@dont-email.me> <11aqect$hpr$1@reader2.panix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 15 Oct 2026 14:57:40 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2635737"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Y+udIQ6M92pEtNA+uoYlD"; posting-host="3f7a5532ffaf673b54a2292b8a86a9eb" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:WatKMm1t+nueChbGHG6EQUya3CY= sha256:wXdB/OP30dNrSktaw3ezLuxIIruZoyD4mKvku7afhtQ= sha1:Z26JyjiVrN6CDpOqJuv4GbYBKcs= sha256:1oORDSode5gIewGoj8fiirDqeEDPQj7Mx9tUGafJ8s0= Content-Language: en-GB In-Reply-To: <11aqect$hpr$1@reader2.panix.com>