[ Next Article |
Previous Article |
Book Contents |
Library Home |
Legal |
Search ]
Communications Programming Concepts
XDR Language Specification
The eXternal Data Representation (XDR) language specification uses an extended Backus Naur form notation for describing the XDR language. The following is a brief description of the notation:
- The following characters are special characters:
| |
A vertical bar separates alternative items. |
( ) |
Parentheses enclose items that are grouped together. |
[ ] |
Brackets enclose optional items. |
, |
A comma separates more than one variable. |
* |
An asterisk following an item means 0 or more occurrences of the item. |
- Terminal symbols are strings of special and nonspecial characters surrounded by " " (double quotation marks).
- Nonterminal symbols are strings of nonspecial characters.
The following specification illustrates the XDR notation:
"a" "very" ("," "very")* ["cold" "and"] "rainy" ("day" | "night")
An infinite number of strings match this pattern, including the following examples:
- "a very rainy day"
- "a very, very rainy day"
- "a very, cold and rainy day"
- "a very, very, very cold and rainy night"
Lexical Notes
The following lexical notes apply to XDR language specification:
- Comments begin with a /* (backslash, asterisk) and terminate with an */ (asterisk, backslash).
- White space is used to separate items and is otherwise ignored.
- An identifier is a letter followed by an optional sequence of letters, digits, or an _ (underscore). Identifiers are case-sensitive.
- A constant is a sequence of one or more decimal digits, optionally preceded by a - (minus sign).
Declarations, Enumerations, Structures, and Unions
The following XDR syntax describes declarations, enumerations, structures, and unions:
declaration:type-specifier identifier
| type-specifier identifier "[" value "]"
| type-specifier identifier "<" [ value ] "<"
| "opaque" identifier "[" value "]"
| "string" identifier "[" value "]"
| type-specifier "*" identifier
|"void"
value:
constant
| identifier
type-specifier:
[ "unsigned" ] "int"
| [ "unsigned" ] "hyper"
| "float"
| "double"
| "bool"
| enum-type-spec
| struct-type-spec
| union-type-spec
| identifier
enum-type-spec:
"enum" enum-body
enum-body:
"{"
( identifier "=" value )
("," identifier "=" value )*
"}"
struct-type-spec:
"struct" struct-body
struct-body:
"{"
( declaration ";" )
( declaration ";" )*
"}"
union-type-spec:
"union" union-body
union-body:
"switch" "(" declaration ")" "{"
( "case" value ":" declaration ";" )
( "case" value ":" declaration ";" )*
[ "default" ":" declaration ";" ]
"}"
constant-def:
"const" identifier "=" constant ";"
type-def
"typedef" declaration ";"
| "enum" identifier enum-body ";"
| "struct" identifier struct-body ";"
| "union" identifier union-body ";"
definition:
type-def
| constant-def
specification:
definition *
Syntax Notes
The following considerations pertain to XDR language syntax:
- The following keywords cannot be used as identifiers:
- bool
- case
- const
- default
- double
- enum
- float
- hyper
- opaque
- string
- struct
- switch
- typedef
- union
- unsigned
- void
- Only unsigned constants can be used as size specifications for arrays. If an identifier is used, it must be declared previously as an unsigned constant in a const definition.
- In the scope of a specification, constant and type identifiers are in the same name space and must be declared uniquely.
- Variable names must be unique in the scope of struct and union declarations. Nested struct and union declarations create new scopes.
[ Next Article |
Previous Article |
Book Contents |
Library Home |
Legal |
Search ]