-
Notifications
You must be signed in to change notification settings - Fork 0
Specification
Felix Schoeller edited this page Sep 8, 2020
·
9 revisions
Table of Contents
This is the reference for the Kantan programming language.
Kantan is a system programming language with the goal of being a modernized version of C. The language is primarily designed for C programmers who want the advancements in programming language design of the last few decades in their language.
The following keywords cannot be used as identifiers.
let return def delegate defer if else import extern export while for struct union enum null undefined new delete sizeof as break continue type
The following keywords are treated in a special way, but are context sensitive and therefore usable as identifiers.
true false
Kantan only specifies line comments, which have to start with //
and reach until the next new line character.
Module = { TopLevelStatement }; TopLevelStatement = FunctionDefinition | TypeDeclaration | ImportStatement | VarDeclStatement; Statement = CompoundStatement | SimpleStatement ";"; CompoundStatement = IfStmt | BlockStmt | WhileStmt | ForStmt; IfStmt = "if" Expression BlockStmt { "else" (IfStmt | BlockStmt) }; WhileStmt = "while" Expression BlockStmt; ForStmt = "for" { SimpleStatement } ";" Expression ";" { SimpleStatement }; BlockStmt = "{" { Statement } "}"; SimpleStatement = VarDeclStatement | ReturnStatement | ControlFlowStatement | DeferableStatement | DeferStatement | ImportStatement; DeferStatement = "defer" DeferableStatement; DeferableStatement = DeleteStatement | ExpressionStatement; ControlFlowStatement = "continue" | "break"; VarDeclStatement = "let" Identifier [ ":" TypeIdentifier ] "=" Expression; DeleteStatement = "delete" Expression; ReturnStatement = "return" Expression; ExpressionStatement = Expression; TypeIdentifier = NamedTypeIdentifier | PointerTypeIdentifier | ArrayTypeIdentifier; ArrayTypeIdentifier = "[" Expression "]" TypeIdentifier; PointerTypeIdentifier = "*" TypeIdentifier; NamedTypeIdentifier = Identifier; FunctionDefinition = ExternDefinition | DelegateDefinition | NormalDefinition; NormalDefinition = ["export"] FunctionSignature BlockStmt; ExternDefinition = "extern" FunctionSignature ";"; DelegateDefinition = "delegate" FunctionSignature ";"; FunctionSignature = "def" [ "(" Parameter ")" ] Identifier "(" [ ParameterList ] ")" [":" TypeIdentifier ]; ParameterList = Parameter { "," Parameter }; Parameter = Identifier ":" TypeIdentifier; TypeDeclaration = "type" Identifier (StructDeclaration | EnumDeclaration | UnionDeclaration); StructDeclaration = "struct" "{" [ FieldList ] "}"; UnionDeclaration = "union" "{" [ FieldList ] "}"; FieldList = Field { "," Field }; Field = Identifier ":" TypeIdentifier ; EnumDeclaration = "enum" "{" [ EnumValueList ] "}"; EnumValueList = EnumValue [ "=" StartValue ] { "," EnumValue }; EnumValue = Identifier; StartValue = LogicOr; ImportStatement = "import" StringLiteral [ "as" Identifier ] ";"; Expression = Assignment | LogicOr; Assignment = Expression ("=" | "+=" | "-=" | "*=" | "/=" | "%=") Expression; LogicOr = LogicAnd { "||" LogicAnd }; LogicAnd = Equality { "&&" Equality }; Equality = Comparison { ("==" | "!=") Comparison }; Comparison = Addition { ("<" | "<=" | ">=" | ">") Addition }; Addition = Multiplication { ("+" | "-") Multiplication }; Multiplication = Unary { ( "*" | "/" | "%" | "as" | "<<" | ">>" ) Unary }; Unary = ("!" | "-" | "*" | "&") Unary | Call; Call = Unit { "(" [ Arguments ] ")" | "." Identifier }; Unit = "true" | "false" | "null" | "undefined" | NumberLiteral | StringLiteral | Identifier | CharLiteral | "(" Expression ")" | "sizeof" TypeIdentifier | "new" Expression | Identifier "{" [ InitList ] "}" | ArrayTypeIdentifier "{" [ InitList ] "}"; InitList = FieldInit { "," FieldInit }; FieldInit = Identifier ":" Expression; Arguments = Expression { "," Arguments }; Identifier = "_" [ { "_" | Digit } Identifier ] | Letter { Letter | Digit | "_" }; Letter = "a".."z" | "A".."Z"; Digit = "0".."9"; StringLiteral = "\"" { Char } "\""; CharLiteral = "'" Char "'"; NumberLiteral = IntLiteral [ "." IntLiteral ]); IntLiteral = Digit { Digit }; Char = A single unicode code point;