Skip to main content

MAL syntax

The MAL syntax is summarized below in extended BNF. Alternative constructs are seperated by | and grouped by parenthesis. Optional parts are marked with square brackets. A repetition is marked with either '+' or '*' to indicate at least once and many times, respectively. Lexical tokens are illustrated in small capitals.

program : (statement ';') *
statement : moduleStmt [helpinfo] | definition [helpinfo]
  | includeStmt | stmt
moduleStmt : MODULE ident | ATOM ident [':'ident]
includeStmt : INCLUDE identifier | INCLUDE string_literal
definition : COMMAND header ADDRESS identifier
  | PATTERN header ADDRESS identifier
  | FUNCTION header statement* END identifier
  | FACTORY header statement* end identifier
helpinfo : COMMENT string_literal
header : [ moduelName '.'] name '(' params ')' result
result : paramType | '(' params ')'
params : binding [',' binding]*
binding : identifier typeName [ props ]
typeName : scalarType | collectionType | ':' any ['_' digit]
scalarType : ':' identifier
collectionType : ':' bat ['[' colType ',' colType ']']
colType : scalarType | anyType
props : '{' property [ ',' property]* '}'
property : identifier [ compare literal]
compare : '=' | '<' | '<=' | '>' | '>=' | '!='
stmt : [tag] varlist [':=' expr ]
tag | RETURN  | BARRIER | CATCH | LEAVE | REDO | RAISE
varlist : variable | '(' variable [',' variable ] * ')'
variable : identifier [ props ]
expr : fcncall | [factor operator] factor
factor : literal_constant | nil | var
fcncall : moduleName '.' name '(' [args] ')'
args : factor [',' factor]*