Skip to content

Language Specification

David Lechner edited this page Feb 6, 2020 · 3 revisions

Grammar

Key

  • "‥": Literal value
  • r"‥": Regular expression
  • <‥>: Composition
  • [‥]: Optional
  • {‥}: Grouping for | or repeat
  • |: Or
  • ...: Repeat zero or more times

Compositions

address-expression

"&" <identifier>

arithmetic-expression

"(" <expression> <operator> <expression> ")"

bang-expression

"!" <expression>

comment

<multi-line-comment> | <single-line-comment>

compilation-unit

{ <define-declaration> | <global-variable-declaration> | <object-declaration> } ...

decimal-literal

r"[0-9]"+

define-declaration

"define" <identifier> <expression>

expression

<address-expression> | <arithmetic-expression> | <bang-expression> | <handle-expression> | <identifier> | <numeric-literal> | <string-literal>

fixed-size-data-type

"DATA8" | "DATA16" | "DATA32" | "DATAF" | "HANDLE"

fixed-size-parameter-type

"IN_8" | "OUT_8" | "IO_8" | "IN_16" | "OUT_16" | "IO_16" | "IN_32" | "OUT_32" | "IO_32" | "IN_F" | "OUT_F" | "IO_F" | "IN_H" | "OUT_H" | "IO_H"

float-literal

<decimal-literal> [ "." <decimal-literal> ] "F"

function-call

<identifier> "(" [ <expression> [ "," <expression> ] ... ] ")"

Note: identifier must be a valid op code

global-variable-declaration

<variable-declaration>

handle-expression

"@" <identifier>

hexadecimal-literal

r"0x[0-9A-Fa-f]+"

identifier

r"[A-Za-z_][A-Za-z_0-9]*"

integer-literal

<decimal-literal> | <hexadecimal-literal>

label

<identifier> ":"

local-variable-declaration

<variable-declaration>

multi-line-comment

r"/*.**/"

numeric-literal

<integer-literal> | <float-literal>

object-declaration

{ "block" | "subcall" | "vmthread" } <identifier> "{" { <local-variable-declaration> | <parameter-declaration> | <function-call> | <label> } ... "}"

Note: parameter-declaration is only allowed for "subcall"

operator

"+" | "-" | "*" | "/"

parameter-declaration

<fixed-size-parameter-type> <identifier>

<variable-size-parameter-type> <identifier> <expression>

Note: expression must resolve to an integer value

single-line-comment

r"//.*$"

string-literal

"'" { r"[ -&(-][-~]" | "\n" | "\q" | "\r" | "\t" } ... "'"

variable-declaration

<fixed-size-data-type> <identifier>

<variable-size-data-type> <identifier> <expression>

variable-size-data-type

"ARRAY8" | "ARRAY16" | "ARRAY32" | "ARRAYF" | "DATAS"

Note: Official compiler also includes "global" for global variable and "local" for local variables but they are not used in practice, so omitting it for now.

variable-size-parameter-type

"IN_S" | "OUT_S" | "IO_S"