Syntax Diagrams

advertisement
Appendix A
Syntax Diagrams
A.1 Introduction
In this appendix, we list a number of syntax diagrams that show how to create the
most important C# constructs that are introduced in this book. Note that this is by
no means a complete grammar of the C# language. It simply serves as an aid in
constructing syntactically correct C# programs.
A.2 Compilation unit
compilation unit
using
library name
;
top-level declaration
437
438
A Syntax Diagrams
A.3 Top-level declaration
top-level declaration
type declaration
namespace
{
name
top-level declaration
}
A.4 Type declaration
439
A.4 Type declaration
type declaration
public
protected
private
internal
abstract
sealed
static
partial
class
name
<
partial
name
>
,
struct
interface
:
class name
,
{
enum
name
{
name
,
}
member
}
;
440
A Syntax Diagrams
A.5 Parameters
parameters
type
name
,
A.6 Member
441
A.6 Member
member
type declaration
public
protected
private
internal
virtual
override
sealed
static
abstract
declaration
type
name
type
{
name
get
;
set
block
name
<
void
>
,
(
class name
:
}
(
base
this
parameters
parameters
(
)
)
expression
,
;
)
block
442
A Syntax Diagrams
A.7 Block
block
instruction
{
}
declaration
A.8 Declaration
declaration
const
type
name
=
initialization
,
A.9 Initialization
initialization
expression
{
initialization
,
}
;
A.10 Type
443
A.10 Type
type
sbyte
byte
float
bool
short
ushort
double
char
int
uint
decimal
string
long
ulong
class name
struct name
<
type
>
,
type
[
]
,
444
A Syntax Diagrams
A.11 Instruction
instruction
type name
method name
expression
(
.
expression
,
property name
variable
=
expression
continue
break
return
expression
switch instruction
if instruction
while instruction
exception
for instruction
block
foreach instruction
A.11.1 If instruction
if instruction
if
(
expression
)
)
instruction
else
instruction
;
A.11 Instruction
445
A.11.2 While instruction
while instruction
while
expression
(
instruction
)
A.11.3 For instruction
for instruction
for
expression
(
;
,
declaration
expression
expression
;
)
instruction
,
A.11.4 Foreach instruction
foreach instruction
foreach
(
type
name
in
expression
instruction
)
446
A Syntax Diagrams
A.11.5 Switch instruction
switch instruction
switch
expression
(
)
{
default
case
declaration
expression
instruction
:
break
;
return
}
A.11.6 Try-catch instruction
exception
try
catch
block
type
(
name
finally
throw
expression
block
;
)
block
A.12 Expression
447
A.12 Expression
expression
new
type name
[
method name
.
(
base
property name
constant
variable
prefix operator
expression
infix operator
postfix operator
(
expression
,
this
(
]
,
type name
expression
expression
expression
type
)
)
expression
expression
as
type
expression
is
type
expression
)
448
A Syntax Diagrams
A.13 Constant
constant
number
true
false
null
‘
symbol
’
“
symbol
”
A.14 Symbol
symbol
\
n
r
t
b
“
‘
\
digit
character
A.15 Number
449
A.15 Number
number
+
E
.
digit
-
digit
f
digit
d
Download