10.1. EBNF Grammar

The Orc language grammar is expressed in Extended Backus-Naur Form (EBNF), with the following meta-notation:

G? denotes zero or one occurrences of G.

G+ denotes one or more occurrences of G.

G sep sep G denotes zero or more occurrences of G, separated by sep.

[1]Expression::= Literal
Variable
Stop
Tuple
List
Record
Call
DotAccess
PrefixOperation
InfixOperation
PostfixOperation
Parallel
Sequence
Prune
Otherwise
Conditional
Lambda
WithDeclaration
WithTypeInformation
TypeOverride
( Expression )
 
[2]Stop::= stop  
[3]Tuple::= ( Expression , , Expression ) Tuple Size ≥ 2 ]
[4]List::= [ Expression , , Expression ]  
[5]Record::= {. Key = Expression , , Key = Expression .}  
[6]Call::= Expression TypeArguments? Arguments  
[7]DotAccess::= Expression.Key  
[8]PrefixOperation::= PrefixOperator Expression  
[9]InfixOperation::= Expression InfixOperator Expression  
[10]PostfixOperation::= Expression PostfixOperator  
[11]Parallel::= Expression | Expression  
[12]Sequence::= Expression >Pattern?> Expression  
[13]Prune::= Expression <Pattern?< Expression  
[14]Otherwise::= Expression ; Expression  
[15]Conditional::= if Expression then Expression else Expression  
[16]Lambda::= lambda TypeParameters? Parameters ReturnType? = Expression  
[17]WithDeclaration::= Declaration Expression  
[18]WithTypeInformation::= Expression :: Type  
[19]TypeOverride::= Expression :!: Type  
[20]Declaration::= DeclareVal #?
DeclareDefinition #?
DeclareDefclass #?
DeclareSignature #?
DeclareSite #?
DeclareClass #?
DeclareInclude #?
DeclareType #?
 
[21]DeclareVal::= val Pattern = Expression  
[22]DeclareDefinition::= def Variable TypeParameters? Parameters ReturnType? Guard? = Expression  
[23]DeclareDefclass::= def class Variable TypeParameters? Parameters ReturnType? Guard? = Expression  
[24]Guard::= if ( Expression )  
[25]DeclareSignature::= def Variable TypeParameters? ArgumentTypes ReturnType  
[26]DeclareSite::= import site Variable = ClassName  
[27]DeclareClass::= import class Variable = ClassName  
[28]DeclareInclude::= include FileName  
[29]DeclareType::= DeclareTypeAlias
DeclareTypeImport
DeclareDatatype
 
[30]DeclareTypeAlias::= type TypeVariable TypeParameters? = Type  
[31]DeclareTypeImport::= import type TypeVariable = ClassName  
[32]DeclareDatatype::= type TypeVariable TypeParameters? = Constructor | | Constructor  
[33]Constructor::= Variable ( Slot , , Slot )  
[34]Slot::= Type_  
[35]Pattern::= WildcardPattern
LiteralPattern
VariablePattern
TuplePattern
ListPattern
RecordPattern
ConsPattern
CallPattern
AsPattern
PatternWithTypeInformation
( Pattern )
 
[36]WildcardPattern::= _  
[37]LiteralPattern::= Literal  
[38]VariablePattern::= Variable  
[39]TuplePattern::= ( Pattern , , Pattern ) Tuple Size ≥ 2 ]
[40]ListPattern::= [ Pattern , , Pattern ]  
[41]RecordPattern::= {. Key = Pattern , , Key = Pattern .}  
[42]ConsPattern::= Pattern : Pattern  
[43]CallPattern::= Variable ( Pattern , , Pattern )  
[44]AsPattern::= Pattern as Variable  
[45]PatternWithTypeInformation::= Pattern :: Type  
[46]Type::= TypeVariable
TupleType
RecordType
FunctionType
TypeApplication
( Type )
 
[47]TupleType::= ( Type , , Type ) Tuple Size ≥ 2 ]
[48]RecordType::= {. Key = Type , , Key = Type .}  
[49]FunctionType::= lambda TypeParameters? ArgumentTypes ReturnType  
[50]TypeApplication::= Type TypeArguments  
[51]Literal::= SignalLiteral
BooleanLiteral
NumberLiteral
CharacterStringLiteral
null
 
[52]SignalLiteral::= signal  
[53]BooleanLiteral::= truefalse  
[54]IntegerLiteral::= DecimalDigit+  
[55]NumberLiteral::= IntegerLiteral DecimalPart? ExponentPart?  
[56]DecimalPart::= . IntegerLiteral  
[57]ExponentPart::= E IntegerLiteral
E+ IntegerLiteral
E- IntegerLiteral
e IntegerLiteral
e+ IntegerLiteral
e- IntegerLiteral
 
[58]CharacterStringLiteral::= "Character+"""  
[59]Variable::= Identifier  
[60]TypeVariable::= Identifier  
[61]Key::= Identifier  
[62]ClassName::= CharacterStringLiteral  
[63]FileName::= CharacterStringLiteral  
[64]Parameters::= ( Pattern , , Pattern )  
[65]TypeParameters::= [ TypeVariable , , TypeVariable ]  
[66]ArgumentTypes::= ( Type , , Type )  
[67]ReturnType::= :: Type  
[68]Arguments::= ( Expression , , Expression )  
[69]TypeArguments::= [ Type , , Type ]  

Tuple Size ≥ 2

A tuple must contain at least two elements. No 0-tuples or 1-tuples are permitted.

10.1.1. Related Links

Related Reference Topics

Related Tutorial Sections