The Scaly Programming Language

Chapter 5

Grammar

This chapter presents the complete grammar of the Scaly programming language in a formal notation. Each production defines a syntactic construct, with nonterminals linking to their definitions.

Notation:

  • identifier, literal — terminal symbols from the lexer

  • 'keyword' — keyword terminals

  • X | Y — alternatives

  • X? — optional

  • X+ — one or more

  • X* — zero or more

Private::='private' Export
Definition::='define' IDENTIFIER GenericParameters? ':'? Attribute* Concept
GenericParameter::=IDENTIFIER Attribute* ','
Class::=Structure ':'? Body? ':'?
Body::='{' Use* Init* DeInit? Member* '}' ':'?
Namespace::='{' Use* Declaration* '}' ':'?
Union::='union' ':'? '(' Variant+ ')' ':'? Body? ':'?
Variant::=IDENTIFIER Attribute* TypeAnnotation? ',' ':'?
Optional::='?'
Parameters::='(' Item* ')'
Item::=IDENTIFIER TypeAnnotation? ',' ':'? Attribute* ':'?
Returns::='returns' Type Attribute*
Throws::='throws' Type Attribute*
Use::='use' Name ':'?
Implement::='implement' Type Attribute* ':'? '{' Use* Method* '}' ':'?
Trait::='trait' Name Extends? Attribute* '{' Use* Method* '}' ':'?
Init::='init' ParameterSet? ':'? Action ':'?
DeInit::='deinit' ':'? Action ':'?
Function::='function' Target
Procedure::='procedure' Target
Operator::='operator' Target
Named::=IDENTIFIER Routine
Extern::='extern'
Instruction::='instruction' ':'?
Intrinsic::='intrinsic' ':'?
Extends::='extends' Extend*
Extend::=Type ','
Macro::='macro' IDENTIFIER Model Operand+
Attribute::=ATTRIBUTE Model ':'?
Module::='module' IDENTIFIER ':'?
Package::='package' Name Version? Source? ':'?
Version::=LITERAL '.' LITERAL
Source::=LITERAL
Initializer::='(' Operand+ ')'
Literal::=LITERAL
Object::='(' Component* ')'
Vector::='[' Element+ ']' Lifetime?
Block::='{' Use* Statement* '}'
If::='if' Operand+ ':' Command Else?
Else::='else' ':'? Command
Match::='match' Operand+ ':' Branch+ Else?
Case::='case' Operand+
While::='while' Condition ':' Label? Action
Choose::='choose' Operand+ ':' When* Else?
Try::='try' Condition ':' When* Else?
When::='when' IDENTIFIER ':' Name ':'? Command ':'?
Let::='let' Binding
Var::='var' Binding
Mutable::='mutable' Binding
Array::='[' Type* ']'
Structure::='(' Part* ')'
Field::='private' Property
Property::=IDENTIFIER TypeAnnotation Initializer? ',' ':'? Attribute* ':'?
Continue::='continue' Loop? ':'?
Break::='break' Loop? Operand* ':'?
Loop::='loop' IDENTIFIER
Return::='return' Operand*
Throw::='throw' Operand*
Lambda::='lambda' Operand+ ':' Action
For::='for' IDENTIFIER TypeAnnotation? 'in' Operand+ ':' Label? Action
Label::='label' IDENTIFIER ':'?
Repeat::='repeat' Label? Action
Set::='set' Operand+ ':' Operand+
SizeOf::='sizeof' Type
Is::='is' Name
Name::=IDENTIFIER Extension*
Extension::='.' IDENTIFIER
Call::='#'
Local::='$'
Reference::='^' IDENTIFIER
Thrown::='!'