Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: rockbrentwood@gmail.com Newsgroups: comp.compilers Subject: Segmentation in programming language grammars .. why? Date: Sun, 29 Dec 2019 21:05:27 -0800 (PST) Organization: Compilers Central Lines: 53 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <19-12-034@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="8146"; mail-complaints-to="abuse@iecc.com" Keywords: parse, design Posted-Date: 30 Dec 2019 11:30:31 EST 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:2415 I see this with many specifications -- redundant non-terminals and rules. I'll illustrate it with a part of the grammar spec for C17. Abbreviate opt, statement, labeled-statement, compound-statement, expression-statement, selection-statement, iteration-statement, jump-statement, block-item, block-item-list, declaration, expression, constant-expression, identifier respectively as ?, S, Sx, Sc, Se, Sb, Sl, Sj, SD, SDs, D, E, Ec, X for The statement grammar is (6.8) S -> Sx | Sc | Se | Sb | Sl | Sj (6.8.1) Sx -> X ':' S Sx -> 'case' Ec ':' S Sx -> 'default' ':' S (6.8.2) Sc -> '{' SDs? '}' SDs -> SD | SDs SD SD -> D | S (6.8.3) Se -> E? ';' (6.8.4) Sb -> 'if' '(' E ')' S Sb -> 'if' '(' E ')' S 'else' S Sb -> 'switch' '(' E ')' S (6.8.5) Sl -> 'while' '(' E ')' S Sl -> 'do' S 'while' '(' E ')' ';' Sl -> 'for' '(' E? ';' E? ';' E? ')' S Sl -> 'for' '(' D E? ';' E? ')' S (6.8.6) Sj -> 'goto' X ';' Sj -> 'continue' ';' Sj -> 'break' ';' Sj -> 'return' E? ';' and is segmented into subgroups Sx, Sc, Se, Sb, Sl, Sj of S. Why? Why not just write it as one segment like this? It's not creating new conflicts in so doing. (6.8) (6.8.1) S -> X ':' S S -> 'case' Ec ':' S S -> 'default' ':' S (6.8.2) S -> '{' SDs? '}' (6.8.3) S -> E? ';' SDs -> SD | SDs SD SD -> D | S (6.8.4) S -> 'if' '(' E ')' S S -> 'if' '(' E ')' S 'else' S S -> 'switch' '(' E ')' S (6.8.5) S -> 'while' '(' E ')' S S -> 'do' S 'while' '(' E ')' ';' S -> 'for' '(' E? ';' E? ';' E? ')' S S -> 'for' '(' D E? ';' E? ')' S (6.8.6) S -> 'goto' X ';' S -> 'continue' ';' S -> 'break' ';' S -> 'return' E? ';'