/
src.8.2.txt
70 lines (68 loc) · 2.54 KB
/
src.8.2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(*
This example defines Extended BNF
informally. Many of the syntax rules include
a comment to explain their meaning; inside a
comment a meta identifier is enclosed in angle
brackets < and > to avoid confusion with
similar English words. The non-terminal symbols
<letter>, <decimal digit> and <character> are
not defined. The position of <comments> is
stated in a comment but not formally defined.
*)
syntax = syntax rule, {syntax rule};
syntax rule
= meta identifier, ’=’, definitions list, ’;’
(* A <syntax rule> defines the sequences of
symbols represented by a <meta identifier> *);
definitions list
= single definition, {’|’, single definition}
(* | separates alternative
<single definitions> *);
single definition = term, {’,’, term}
(* , separates successive <terms> *);
term = factor, [’-’, exception]
(* A <term> represents any sequence of symbols
that is defined by the <factor> but
not defined by the <exception> *);
exception = factor
(* A <factor> may be used as an <exception>
if it could be replaced by a <factor>
containing no <meta identifiers> *);
factor = [integer, ’*’], primary
(* The <integer> specifies the number of
repetitions of the <primary> *);
primary
= optional sequence | repeated sequence
| special sequence | grouped sequence
| meta identifier | terminal string | empty;
empty = ;
optional sequence = ’[’, definitions list, ’]’
(* The brackets [ and ] enclose symbols
which are optional *);
repeated sequence = ’{’, definitions list, ’}’
(* The brackets { and } enclose symbols
which may be repeated any number of times *);
grouped sequence = ’(’, definitions list, ’)’
(* The brackets ( and ) allow any
<definitions list> to be a <primary> *);
terminal string
= "’", character - "’", {character - "’"}, "’"
| ’"’, character - ’"’, {character - ’"’}, ’"’
(* A <terminal string> represents the
<characters> between the quote symbols
’_’ or "_" *);
meta identifier = letter, {letter | decimal digit}
(* A <meta identifier> is the name of a
syntactic element of the language being
defined *);
integer = decimal digit, {decimal digit};
special sequence = ’?’, {character - ’?’}, ’?’
(* The meaning of a <special sequence> is not
defined in the standard metalanguage. *);
comment = ’(*’, {comment symbol}, ’*)’
(* A comment is allowed anywhere outside a
<terminal string>, <meta identifier>,
<integer> or <special sequence> *);
comment symbol
= comment | terminal string | special sequence
| character;