From: Yury Chumak <sfynkx@gmail.com>
To: 9front@9front.org
Subject: Re: [9front] Bug in rc
Date: Thu, 27 Apr 2023 05:05:13 +0300 [thread overview]
Message-ID: <CAOe=0de4LQVYF83hLdAfO6HkyKsjNJtEtK0nq8ik84sUCfFWHA@mail.gmail.com> (raw)
In-Reply-To: <7BAAF1BDE05AF95E8E1167B980AD0CDA@eigenstate.org>
Hitting limit is a half decision. In general, a strange decision is to
implement such non-limiting constructions using recursion. By the way,
in my real code there is a limit of 141 'case'-blocks, but there are
complex 'case' conditions in the blocks - apparently they are
additionally expanded.. So the test example is ideal at maximum, but
really the limit can be reached faster.
чт, 27 апр. 2023 г. в 03:46, <ori@eigenstate.org>:
>
> Quoth Yury Chumak <sfynkx@gmail.com>:
> > Hello all..
> >
> > Noticed that rc returns error 'stack overflow' if code consists
> > 'switch' construction with big amount of 'case' blocks. Steps to
> > reproduce:
> >
> > 1.Generate test script by next code:
> > #!/bin/rc
> > echo '#!/bin/rc' >test.rc
> > echo 'switch($*){' >>test.rc
> > for(i in `{seq 1 250}){
> > echo ' case ' $i>>test.rc
> > echo ' echo number ' $i>>test.rc
> > }
> > echo ' case *' >>test.rc
> > echo ' echo number none'>>test.rc
> > echo '}'>>test.rc
> >
> > 2. Run result script:
> > % chmod +x test.rc
> > % test.rc
> > ./test.rc:497: token 248: yacc stack overflow
> >
> > The 'switch' construction works normaly with number 'case' block less than 247.
> > In comparison linux's bash has no limitation to number elements in
> > 'case' block (at least 500k tested).
> >
>
> Yes, the grammar for this is right recursive,
> which means the full stack is collected before
> it's reduced:
>
> body: cmd
> | cmdsan body {$$=tree2(';', $1, $2);}
>
> You can play around with refactoring it to be
> left recursive, or maybe bringing in the C rewrite
> of the parser from plan9port (ideally with tests).
>
> But I'm not sure why it matters; you can hit a
> limit with a huge switch, but it doesn't seem
> like a limit for practical code.
>
--
Sphynkx
next prev parent reply other threads:[~2023-04-27 9:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-26 18:20 Yury Chumak
2023-04-27 0:44 ` ori
2023-04-27 2:05 ` Yury Chumak [this message]
2023-04-27 2:15 ` Anthony Martin
2023-04-27 3:09 ` Yury Chumak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAOe=0de4LQVYF83hLdAfO6HkyKsjNJtEtK0nq8ik84sUCfFWHA@mail.gmail.com' \
--to=sfynkx@gmail.com \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).