EBNF: A Notation for Describing Syntax. n Languages and Syntax n EBNF Descriptions and Rules n More Examples of EBNF n Syntax and Semantics n EBNF Description of Sets n Advanced EBNF (recursion). Quote of the Day.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
nLanguages and Syntax
nEBNF Descriptions and Rules
nMore Examples of EBNF
nSyntax and Semantics
nEBNF Description of Sets
nAdvanced EBNF (recursion)
“When teaching a rapidly changing technology, perspective is more important than content.”
EBNF is a notation for formally describing syntax: how to write symbols in a language. We will use EBNF to describe the syntax of Java. But there is a more compelling reason to begin our study of programming with EBNF: it is a microcosm of programming. There is a strong similarity between the control forms of EBNF and the control structures of Java: sequence, decision, repetition, recursion, and the ability to name descriptions. There is also a strong similarity between the process of writing EBNF descriptions and writing Java programs. Finally studying EBNF introduces a level of formality that will continue throughout the semester.
digitÜ 0123456789
integerÜ [+]digit{digit}
digit is defined as any of the alternatives0 through 9
integer is defined as a sequence of three items: (1) an optional sign (if it is included, it must be the alternative+ or ), followed by (2) any digit, followed by (3) a repetition of zero or more digits.
The integer RHS combines and illustrates all EBNF
control forms: sequence, option, alternative, repetition.
In the integer EBNF rule, start with the optional sign; discard the option. Next in the sequence is a digit: choose the 7 alternative. Next in the sequence is a repetition; choose 0 repetitions. End of symbol & integer reached.
In the integer EBNF rule, start with the optional sign; include the option; choose the + alternative. Next in the sequence is a digit: choose the 1 alternative. Next in the sequence is a repetition; choose 2 repetitions; choose the 2 alternative for the first; choose the 7 alternative for the second. End of symbol & integer reached.
Tabular Proof Replacement Rules
(1) Replace a name (LHS) by its definition (RHS)
(2) Choose an alternative
(3) Include or Discard an Option
(4) Choose the number of repetitions
Status Reason
integerGiven
[+]digit{digit} Replace LHS by RHS (1)
[+]digit{digit} Chose + alternative (2)
+digit{digit} Include option (3)
+1{digit} Replace digit by 1 alternative (1&2)
+1digit digitChoose two repetitions (4)
+12digitReplace digit by 2 alternative (1&2)
+127 Replace digit by 7 alternative (1&2)
integer
[+]
digit
{digit}
[+]
1
digit
digit
+
2
7
A graphical proof replaces multiple (equivalent) tabular proofs, since the order of rule application (which is unimportant) is often absent in graphical proofs.
signÜ +
digitÜ 0123456789
integerÜ [sign]digit{digit}
xÜ +
yÜ 0123456789
zÜ [x]y{y}
These two descriptions are not identical but they are equivalent: Although they use different EBNF rule names (consistently), asking whether a symbol is an integer is the same as asking whether the symbol is a z.
A “simplified but equivalent” definition of integer?
signÜ +
digitÜ 0123456789
integerÜ [sign]{digit}
A “good” definition of integers with commas (1,024)?
signÜ +
commadigitÜ 0123456789,
commaintegerÜ [sign]commadigit{commadigit}
Both definitions classify “nonobvious” symbols as legal integer or commainteger. Find such symbols.
Allow nonadjacent embedded underscores to add a special structure to a number
2_10_54
1_800_555_1212
1_000_000 (compared to 1000000; figure each value fast)
Define structuredinteger
digitÜ 0123456789
structuredintegerÜ [sign]digit{[_]digit}
Semantically, the underscore is ignored
1_2 has the same meaning as 12
How can we fix the date problem: 12_5_1987 and 1_25_1987
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
+

integer
Which Syntax chart for integer is simpler? The previous one (because it is smaller) or this one (because it it doesn’t need another name for digit)?
integerlistÜinteger{,integer}
integersetÜ ([integerlist])
Status Reason
integersetGiven
([integerlist]) Replace integerset by its RHS
(integerlist) Include option
(integer{,integer}) Replace integerlist by its RHS
(5{,integer}) Lemma: 5 is an integer
(5,integer,integer) Choose two repetitions
(5,2,integer) Lemma: 2 is an integer
(5,2,11) Lemma: 11 is an integer
integerrangeÜinteger[..integer]
integerlistÜintegerrange{,integerrange}
integersetÜ ([integerlist])
A directly recursive EBNF rule has its LHS in its RHS
r1Ü Ar1
We read this as r1 is defined as the choice of nothing or an A followed by an r1. The symbols recognized as an r1 are of the form An, n³ 0. Proof that AAA is an r1
r1Given
Ar1Replace r1 by the second alternative in its RHS
AAr1Replace r1 by the second alternative in its RHS
AAAr1Replace r1 by the second alternative in its RHS
AAA Replace r1 by the first (empty) alternative in its RHS
This rule is equivalent to r1Ü{A}
To recognize symbols of the form form An Bn , n³ 0 we cannot write r1Ü{A}{B}, because nothing constrains us choosing different repetitions of A and B: AAB
The recursive rule r1Ü Ar1B works, because each choice of the second alternative uses exactly one A and one B. Proof that AAABBB is an r1
r1Given
Ar1B Replace r1 by the second alternative in its RHS
AAr1BB Replace r1 by the second alternative in its RHS
AAAr1BBB Replace r1 by the second alternative in its RHS
AAABBB Replace r1 by the first (empty) alternative in its RHS
Symbols of the form form An Bn , n³ 0
Read the EBNF Handout (all but Section 2.7)
See next slide for more problems