dotLang

A minimal but powerful programming language based on C, Go and Haskell

View the Project on GitHub

EBNF-like grammar

Legend

Format:

Result  ::= component1 ( component2 | component3 ) | component4 | [component5] component6
- /* comments */
- 'literal'
- (A|B): either of A or B
- A B: A then B
- [A]: Optional A
- (A)* : Repeating A zero or more times
- (A)+ : Repeating A one or more times
- {A}  : Repeating A zero or more times, separated with comma

Main parts

Module                  ::= ( ImportDecl | TypeDecl | BindingDecl )*  

Naming basics

TypeName                ::= CAPITAL_LETTER CHAR*
BindingName             ::= ['_test'] (CHAR|'_')*
ModuleAlias             ::= (CHAR|'_')*

Import

ImportDecl              ::= ImportAliasDecl | ImportSelectiveDecl  
ImportAliasDecl         ::= [ ModuleAlias '=' ] Import  
Import                  ::= 'import' '(' ImportString ')'
ImportSelectiveDecl     ::= { BindingName } '=' Import '..' '{' { BindingName } '}'
ImportString            ::= STRING | BindingName | STRING '+' StringLiteral       

Type Declaration

TypeDecl                ::= TypeName (':'|'=') TypeLiteral
TypeLiteral             ::= PrimitiveType | StructType | UnionType | FnType | SeqType | MapType | EnumType | TypeName
PrimitiveType           ::= 'int' | 'float' | 'string' | 'char' | 'byte' | 'bool' | 'nothing'
StructType              ::= 'struct' '(' FieldList ')'
FieldList               ::= { [ Identifier ':' ] Type }
UnionType               ::= (Type '|' Type) | (Type '|' UnionType)
FnType                  ::= 'fn' '(' { Type } '->' Type ')'
SeqType                 ::= '[' Type ']'
MapType                 ::= '[' Type ':' Type ']'
EnumType                ::= 'enum' SeqLiteral

Binding Declaration

BindingDecl             ::= { BindingNameItem } '=' Expression
BindingNameItem         ::= BindingName [ ':' Type ] | '_'
Expression              ::= EqExpression     { ('and'|'or') EqExpression }
EqExpression            ::= CmpExpression    { ('=='|'!=') CmpExpression }
CmpExpression           ::= ShiftExpression  { ('>'|'<'|'>='|'<=') ShiftExpression }
ShiftExpression         ::= AddExpression    { ('>>'|'<<'|'^') AddExpression }
AddExpression           ::= MulExpression    { ('+'|'-') MulExpression }
MulExpression           ::= UnaryExpression  { ('*'|'/'|'%'|'%%') UnaryExpression }
UnaryExpression         ::= ['not'|'-']      BasicExpression
BasicExpression         ::= ['('] PrimaryExpression [')']
PrimaryExpression       ::= Literal | Identifier | StructAccessExpression | MapSeqAccessExpression | 
                                ModuleAccessExpression | FnCallExpression | StructExpression | LambdaCreatorExpression | FnDeclaration
StructAccessExpression  ::= Expression '.' Identifier
MapSeqAccessExpression  ::= Expression '[' Expression ']'
ModuleAccessExpression  ::= ( Import | Identifier ) '..' Identifier
FnCallExpression        ::= Expression '(' { Expression } ')'
StructExpression        ::= ( TypeName | StructType) '(' FieldValueList ')'
FieldValueList          ::= { [ Identifier ':' ] Expression }
LambdaCreatorExpression ::= Expression '(' { Expression | '_' } ')'
FnDeclaration           ::= 'fn' ['(' { Identifier ':' Type } '->' Type ')'] '{' Expression+ '}'

Literal                 ::= IntLiteral | FloatLiteral | CharLiterl | StringLiteral | NothingLiteral | 
                                BoolLiteral | SeqLiteral | MapLiteral | StructLiteral | TypeLiteral

To Be Added Later