Sujet : Re: Whaddaya think?
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 19. Jun 2024, 02:58:57
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240618181840.18@kylheku.com>
References : 1 2 3 4 5 6 7 8 9
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-06-19, Keith Thompson <Keith.S.Thompson+
u@gmail.com> wrote:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
Kaz Kylheku <643-408-1753@kylheku.com> writes:
>
Speaking of while, the do/while construct does not require parentheses
in order to disambiguate anything, since it has a mandatory semicolon.
Yet, it still has them.
>
It has them to allow an extension for a "loop-and-a-half" control
structure:
>
do statement while ( expression ) statement
>
and so for example
>
do c = getchar(); while( c != EOF ) n++;
>
to count characters on standard input.
>
Oh? Do you have any evidence that that was the intent? [...]
>
I think you're reading something into my remark that it
didn't say.
>
Or at least that you didn't mean.
FWIW, it would seem that the phrase pattern:
do statement while expression ;
may be compatible with the proposed extension in a way
manageable via LALR(1) parsing.
I don't see difficulties in recursive descent, either.
The near minimal Yacc grammar pasted below produces no conflicts,
and is only slightly contorted. We treat the ')' token as the
lowest prededence operator, and ';' as highest, which eliminates
conflicts in way that we want.
I can explain why; another way is to remove the %nonassoc declarations,
use "yacc -v", and study the confict details y.output file.
It's not clear whether the grammar can be nicely factored into the form
used in the standard, which makes no use of precedence or associativity.
(But would that be a requirement for leaving room for an extension.)
%{
%}
%nonassoc ')'
%token DO WHILE NUM
%left '+'
%nonassoc ';'
%%
while_statement : DO statement WHILE expr ';'
| DO statement WHILE '(' expr ')' statement
statement : ';'
| expr ';'
| '{' expr '}'
| '{' '}'
;
expr : '(' expr ')'
| expr '+' expr
| '+' expr
| NUM
;
%%
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca