Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #2415
| From | rockbrentwood@gmail.com |
|---|---|
| Newsgroups | comp.compilers |
| Subject | Segmentation in programming language grammars .. why? |
| Date | 2019-12-29 21:05 -0800 |
| Organization | Compilers Central |
| Message-ID | <19-12-034@comp.compilers> (permalink) |
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? ';'
Back to comp.compilers | Previous | Next — Next in thread | Find similar
Segmentation in programming language grammars .. why? rockbrentwood@gmail.com - 2019-12-29 21:05 -0800 Re: Segmentation in programming language grammars .. why? Kaz Kylheku <493-878-3164@kylheku.com> - 2019-12-30 18:04 +0000
csiph-web