Table of Contents

Grammar for Refu in ABNF format. I know that it does not look really good in html format. Will try to fix it when possible.

Terminal rules (tokens)

TOKENKWCONST = "const" TOKENKWTYPE = "type" TOKENKWFUNCTION = "fn" TOKENKWIF = "if" TOKENKWELIF = "elif" TOKENKWELSE = "else"

TOKENSMCOLON = ":" TOKENSMOCBRACE = "{" TOKENSMCCBRACE = "}" TOKENSMOPAREN = "(" TOKENSMCPAREN = ")"

TOKENOPPLUS = "+" TOKENOPMINUS = "-" TOKENOPMULTI = "*" TOKENOPDIV = "/" TOKENOPINC = "++" TOKENOPDEC = "–" TOKENOPASSIGN = "=" TOKENOPEQ = "=" TOKEN_OP_NEQ = "!" TOKENOPGT = ">" TOKENOPGTEQ = ">=" TOKENOPLT = "<" TOKENOPLTEQ = "<=" TOKENOPTYPESUM = "|" TOKENOPCOMMA = "," TOKENOPIMPL = "->" TOKENOPLOGICAND = "&&" TOKENOPLOGICOR = "||"

EMPTY = ""

Non terminal rules

root = statements statements = *statement statement = block / functiondeclaration / modulesignature / moduleimplementation / interfacedeclaration / interfaceimplementation / datadeclaration / variabledeclaration

expression = identifier / stringliteral / numeric / ifexpression / binaryopexpression / unaryopexpression

expressionlist = expression / expressionlist "," expression

binaryop = "=" "+" "*" "/" "%" ">" ">=" "<" "<=" "=" "!" binaryopexpression = expression binaryop expression

unaryop = "&" "*" "!" "++" "–" unaryopexpression = unaryop expression

block = "{" statements "}"

moduledeclaration = signature identifier block moduleimplmentation = identifier "implof" identifier block

identifierslist = identifier / identifierslist "," identifier genericattributes = "<" identifierslist ">" generictype = "type" / OTHERS genericargumentslist = identifier ":" generictype / genericargumentslist "," identifier ":" generictype genericdeclaration = "<" genericargumentslist ">"

arrayattributes = numeric arraydeclaration = "[" arrayattributes"]"

memoryattributes = arraydeclaration / "*" / "&" / "ptr[~]" / "ptr[@]"

typedescription = typeterm typedescription'

typedescription' = TOKENOPIMPL typeterm typedescription' / EMPTY

typeterm = typefactor typeterm'

typeterm' = TOKENOPTYPESUM typefactor typeterm' / EMPTY

typefactor = typeelement typefactor'

typefactor' = TOKENOPIMPL typeelement typefactor' / EMPTY

typeelement = TOKENSMOPAREN typedescription TOKENSMCPAREN / identifier TOKENSMCOLON annotatedidentifier / annotatedidentifier

typedeclaration = TOKENKWTYPE TOKENSMOCBRACE typedescription TOKENSMCCBRACE

typedeclaration = identifier [genericattributes] decoratedtypedeclaration = [memoryattributes] typedeclaration variabledeclaration = identifier ":" decoratedtypedeclaration

dataoptoken = "," / "|" / "->" dataop = datadesc dataoptoken datadesc datadesc = dataop / identifier ":" datadesc / identifier

datadeclaration = "data" identifier [genericdeclaration] "{" datadesc "}"

variablelist = variabledeclaration / variablelist "," variabledeclaration

functiondeclaration = "fn" identifier [genericdeclaration] "(" variablelist ")" ["->" decoratedtypedeclaration] functionimplementation = functiondeclaration block functioncall = identifier [genericattributes] "(" expressionlist ")"

interfacedeclaration = "interface" identifier [genericdeclaration] "{" 1*functiondeclaration"}" interfaceimplementation = "implof" identifier functionimplementation