From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 10719 invoked from network); 27 Apr 2023 00:45:34 -0000 Received: from 9front.inri.net (168.235.81.73) by inbox.vuxu.org with ESMTPUTF8; 27 Apr 2023 00:45:34 -0000 Received: from mimir.eigenstate.org ([206.124.132.107]) by 9front; Wed Apr 26 20:44:21 -0400 2023 Received: from abbatoir (pool-108-27-53-161.nycmny.fios.verizon.net [108.27.53.161]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id 90fd1971 (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Wed, 26 Apr 2023 17:44:19 -0700 (PDT) Message-ID: <7BAAF1BDE05AF95E8E1167B980AD0CDA@eigenstate.org> To: 9front@9front.org Date: Wed, 26 Apr 2023 20:44:17 -0400 From: ori@eigenstate.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: leveraged optimized database-based firewall Subject: Re: [9front] Bug in rc Reply-To: 9front@9front.org Precedence: bulk Quoth Yury Chumak : > 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.