Context-Free Grammar
DC File
The DC File
is the root production of the grammar.
The root production is made up of one or more type
declarations.
In Panda, historically, each type declaration could
optionally be terminated with a semicolon (;
) token.
In libdonet, every type declaration (excluding Python-style
imports) requires a semicolon delimiter.
(* Root production of the grammar *)
dc file = type declaration, { type declaration };
type declaration = python import | (keyword decl, ';') | (typedef decl, ';') | (dclass decl, ';') | (struct decl, ';');
Python-style Import
python import = py modules, py symbols;
py modules = 'from', identifier, { '.', identifier }, view suffixes;
py symbols = 'import', ( '*' | ( identifier, view suffixes ) );
view suffixes = { '/', view suffix };
Keyword
(* Can be a historical DC keyword or a defined one. *)
keyword decl = 'keyword', ( identifier | dc keyword );
keyword list = { identifier | dc keyword };
Type Definition
typedef decl = 'typedef', nonmethod type with name, [ '[', array range, ']' ];
Struct
struct decl = 'struct', identifier, '{', struct fields, '}';
struct fields = { struct field, ';' };
struct field = switch decl | unnamed field | named field;
Distributed Class
dclass decl = 'dclass', identifier, parents, '{', class fields, '}';
parents = ':', identifier, { ',', identifier };
class fields = { class field, [ ';' ] };
class field = atomic field | molecular field;
Class Fields
atomic field = named field, keyword list;
molecular field = identifier, ':', identifier, { ',', identifier };
Switch
switch decl = 'switch', '(', parameter, ')', '{', switch fields, '}';
switch fields = { switch case | ( type value, ';' ) | ( named field, ';' ) | ( 'break', ';' ) };
switch case = ( ( 'case', type value ) | 'default' ), ':';