Freigeben über


Cord Syntax Definition

The syntax definition of the Cord scripting language follows.

CordScript ::= { UsingClause } { Configuration | Machine } .
UsingClause ::= using QualIdent ; .

Configuration ::= config Ident [ : ConfigList ] { { ConfigClause ; } } .
ConfigClause ::= ActionClause | DomainClause | BoundClause | SwitchClause .
ConfigList ::= ConfigId { , ConfigId } . // List of ancestor configurations
ConfigId ::= Ident .
ActionClause ::= ImportActions | DeclaredAction .
ImportActions ::= action all [ public | internal ] Type /*Implementation type*/ .
DeclaredAction ::= action [ exclude | abstract ] [ event ] [ [ Namespace. ] Class. ] [ [ Namespace. ] Class. ] Method [ where ConstraintList ] .
Method ::= [ static ] Type [ QualIdent ] ( [ ParameterList ] ) .
ParameterList ::= [ out | ref ] VarDeclaration { , [out | ref ] VarDeclaration } .
VarDeclaration ::= Type Ident .
DomainClause ::= domain Type = Domain .
BoundClause ::= bound Type = (none | Number) .
SwitchClause ::= switch Switch .
Switch ::= Ident = ( Literal | Ident | none ) .

Machine ::= machine Ident ( [ ParameterList ] ) [ / VarDeclaration /*Ret Val Declaration*/ ] : ConfigList
[ where Switch {, Switch } ] { Behavior } .
Behavior ::= // In increasing binding priority; binary default is left-associative
LetBehavior | BindBehavior | ConstructBehavior | Invocation | UniversalBehavior | ParallelBehavior
| PermutationBehavior | UnionBehavior | SequencingBehavior | PreconstraintBehavior
| RepetitionBehavior | PostConstraintBehavior | HidingBehavior | GroupedBehavior .
LetBehavior ::= let LocalVarList [ where ConstraintList ] in Behavior .
LocalVarList ::= VarDeclaration { , VarDeclaration } .
ConstraintList ::= ( Ident in Domain { , Ident in Domain } ) | EmbeddedCode .
BindBehavior ::= bind InvocationList in Behavior .
ConstructBehavior ::= construct ConstructKind [ from Ident ] [ where Switch { , Switch } ]
[ with EmbeddedCode ] [ for Behavior ] .
ConstructKind ::= Ident { Ident } .
UniversalBehavior ::= ( ... | _ ) .
ParallelBehavior ::= Behavior ( || | |?| | ||| ) Behavior .
PermutationBehavior ::= Behavior & Behavior .
UnionBehavior ::= Behavior | Behavior .
SequencingBehavior ::= Behavior -> Behavior | Behavior ; Behavior /*right-assoc*/ .
PreconstraintBehavior ::= EmbeddedCode : Behavior .
RepetitionBehavior ::= Behavior ( * | + | ? ) | Behavior { Number [, [ , Number] ] } .
PostconstraintBehavior ::= Behavior : ( EmbeddedCode | fail ) .
HidingBehavior ::= Behavior ( reduce | collapse | internalize ) ConfigId .
GroupingBehavior ::= ( Behavior ) .

InvocationList ::= Invocation { , Invocation } .
Invocation ::= [ ! ] [ AtomicQualifier ] Target [ ( ArgList ) ] [ / Expression ] .
AtomicQualifier ::= call | return | event .
Target := new [ Expression . ] Type | Expression . Ident | QualIdent .
ArgList ::= [ out | ref ] Expression { , [ out | ref ] Expression } .

Expression ::= ( Type ) Expression | QualIdent | Literal | _ | Domain | StructuredValue .
StructuredValue ::= Type ( StructuredValueArgumentList | StructuredValueCollectionSpec ) .
StructuredValueArgumentList ::= ( [ NamedPatternList ] ) .
StructuredValueCollectionSpec ::= { [ MapletOrExprList ] } .
NamedPatternList ::= NamedPattern { , NamedPattern } .
NamedPattern ::= Ident = Expression .
MapletOrExprList ::= Expression { , Expression } | Maplet { , Maplet } .
Maplet ::= Expression -> Expression .
QualIdent ::= QualIdent . Ident | Ident .

Domain ::= Domain + Domain | EmbeddedCode | instances Type | { [ ElementList ] } | CollectionBySizeDomain .
CollectionBySizeDomain ::= Type [ Literal [ .. Literal ] ] .
ElementList ::= Element { , Element } .
Element ::= Expression [ .. Expression ] .
EmbeddedCode ::= (. CSharpExpr .) | {. CSharpStm .} .

Type ::= SimpleType { [ { , } ] } .
SimpleType ::= PrimitiveType | [ SimpleType . ] Ident [ < TypeList > ] .
TypeList ::= Type { , Type } .
PrimitiveType ::= sbyte | byte | short | ushort | int | uint | long | ulong | char | float
| double | bool | object | string | void .
Literal ::= String | Number | true | false | null .
IdentList ::= Ident { , Ident } .
Ident ::= /* as in C# */
String ::= /* as in C# */
Number ::= /* as in C# */

Precedence

The behavior operators are defined above in reverse precedence order (that is, from least to most precedence). For example, | has less precedence than ; which has less precedence than ? and so on. Thus,
BehaviorA? | (BehaviorB? ; (BehaviorA? | BehaviorB?))
expresses the same resultant behavior as
BehaviorA? | BehaviorB? ; (BehaviorA? | BehaviorB?)

Meta-Symbols Used

Symbol Used For Example Example Meaning

::=

nonterminal definition

A ::= a b c .

A is the defined nonterminal

.

end of definition

A ::= a b c .

period denotes end

|

separating alternatives

a b | c d | e

a b or c d or e

( )

grouping alternatives

(a | b) c

a c or b c

[ ]

option (none or one time)

[ a ] b

b or a b

{ }

iteration (none or more times)

{ a } b

b or a b or a a b or ...

//

commenting on a line

// Comment…

applies to entire line

/* */

commenting on an item

/*Comment*/

applies to preceding item

These meta-symbols are based on the Extended Backus-Naur Form (EBNF) notation for syntax description. Identifiers with a lowercase first letter denote terminals in the described language. Terminal identifiers and other terminal characters are shown in bold for emphasis. Identifiers with an uppercase first letter denote nonterminal artifacts in the syntax definition. Nonterminal identifiers are named to suggest the meaning of their productions in the context of Cord programs. Many of them in the above definition are links to separate topics containing more details on their meaning in Cord scripts.

See Also

Other Resources

Cord Scripting Language