Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #2415 > unrolled thread

Segmentation in programming language grammars .. why?

Started byrockbrentwood@gmail.com
First post2019-12-29 21:05 -0800
Last post2019-12-30 18:04 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.compilers


Contents

  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

#2415 — Segmentation in programming language grammars .. why?

Fromrockbrentwood@gmail.com
Date2019-12-29 21:05 -0800
SubjectSegmentation in programming language grammars .. why?
Message-ID<19-12-034@comp.compilers>
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? ';'

[toc] | [next] | [standalone]


#2416

FromKaz Kylheku <493-878-3164@kylheku.com>
Date2019-12-30 18:04 +0000
Message-ID<19-12-035@comp.compilers>
In reply to#2415
On 2019-12-30, rockbrentwood@gmail.com <rockbrentwood@gmail.com> wrote:
> 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.

They want to maintain hierarchical categories like "iteration statement"
and "selection statement" as part of the language definition.

There is some advantage in this when documenting, because the grammar
fragment given in each section is understood to be complete.

That is to say, in the document section on selection statements, say,
the grammar fragment which defines selection-statement is complete in
the sense that nothing else in the document is a selection-statement.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.compilers


csiph-web