From: ori@eigenstate.org
To: 9front@9front.org
Subject: Re: [9front] Bug in rc
Date: Wed, 26 Apr 2023 20:44:17 -0400 [thread overview]
Message-ID: <7BAAF1BDE05AF95E8E1167B980AD0CDA@eigenstate.org> (raw)
In-Reply-To: <CAOe=0ddPe5nk9VQkO-t+VXPDpf2+Si_s2-iH3VpBhDny7ieehg@mail.gmail.com>
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.
next prev parent reply other threads:[~2023-04-27 0:45 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 [this message]
2023-04-27 2:05 ` Yury Chumak
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=7BAAF1BDE05AF95E8E1167B980AD0CDA@eigenstate.org \
--to=ori@eigenstate.org \
--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).