Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: anton@mips.complang.tuwien.ac.at (Anton Ertl) Newsgroups: comp.compilers Subject: Re: Deep expression chain performance Date: Thu, 27 Apr 2023 06:17:51 GMT Organization: Institut fuer Computersprachen, Technische Universitaet Wien Sender: johnl@iecc.com Approved: comp.compilers@iecc.com Message-ID: <23-04-016@comp.compilers> References: <23-04-012@comp.compilers> <23-04-015@comp.compilers> Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="11079"; mail-complaints-to="abuse@iecc.com" Keywords: parse, performance Posted-Date: 27 Apr 2023 21:56:22 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:3457 Kaz Kylheku <864-117-4973@kylheku.com> writes: >ISO C specifies its grammar in an obtusely verbose way, similar to the >above. The reason is that it makes the grammar unambiguous, meaning >that it does not require any annotation or external remarks about >ambiguities having to be resolved by a certain associativity or >precedence. They were not that keen on eliminating ambiguity. The classical ambiguous grammar rule is there: |selection-statement: | if ( expression ) statement | if ( expression ) statement else statement | switch ( expression ) statement They resolve that ambiguity in prose: |An else is associated with the lexically nearest preceding if that is |allowed by the syntax. C is not alone in this approach. As for why they chose to deal with expressions through BNF, my guess is that it allowed them to split the expression syntax into different sections, each with their own piece of the grammar, rather than having a section on the syntax that presents an ambuguous BNF and resolves the ambiguity in prose (and by necessity has to cover the whole expression syntax), and then having sections on the semantics of the various expression sub-syntaxes. - anton -- M. Anton Ertl anton@mips.complang.tuwien.ac.at http://www.complang.tuwien.ac.at/anton/