primary
primary ::= "(" expression ")"
| "[" expression ("," expression)* "]"
| "{" string ":" expression ("," string ":" expression)* "}"
| integer
| real
| string
| function
| name
| "super" "." name
Language Reference
Below is a formal expression of the ObjectTalk scripting language in Extended Backus–Naur Form (EBNF). You can read more about this notation on Wikipedia. The pretty diagrams were created using the "RailRoad Diagram Generator" which translates EBNF into HTML with pictures. This tool is highly recommended for visualizing grammar.
module ::= statement*
statement ::= expression ";"
| block
| "var" name ("=" expression)? ";"
| "class" name ":" expression block
| "function" name "(" ((name ("," name)*)?) ")" block
| "if" expression block ("elif" expression block)* ("else" block)?
| "while" expression block
| "do" block "while" expression ";"
| "for" name "in" expression block
| "throw" expression ";"
| "try" block "catch" name block
| "return" expression ";"
block ::= "{" statement* "}"
expression ::= conditional (
"=" expression |
"*=" expression |
"/=" expression |
"%=" expression |
"+=" expression |
"-=" expression |
"|=" expression |
"^=" expression |
"&=" expression)*
conditional ::= or ("?" expression ":" expression)?
or ::= and ("||" and)*
and ::= bytewise-or ("&&" bytewise-or)*
bytewise-or ::= bytewise-xor ("|" bytewise-xor)*
bytewise-xor ::= bytewise-and ("^" bytewise-and)*
bytewise-and ::= equal ("&" equal)*
equal ::= relation ("==" relation | "!=" relation)*
relation ::= shift (
"<" shift |
"<=" shift |
">" shift |
">=" shift |
"in" shift |
"not in" shift)*
shift ::= addition ("<<" addition | ">>" addition)*
addition ::= multiplication ("+" multiplication | "-" multiplication)*
multiplication ::= prefix ("*" prefix | "/" prefix | "%" prefix)*
prefix ::= ("-" | "!" | "^" | "++" | "--")? postfix
postfix ::= primary ("[" expression "]" | "(" expression ("," expression)* ")" | "." name | "++" | "--")*
primary ::= "(" expression ")"
| "[" expression ("," expression)* "]"
| "{" string ":" expression ("," string ":" expression)* "}"
| integer
| real
| string
| function
| name
| "super" "." name
integer ::= [-+]? ([1-9][0-9]* | "0"[Bb][01]+ | "0"[Oo][0-7]+ | "0"[Xx][0-9A-Fa-f]+ | "0"[0-7]*)
real ::= [-]? [0-9][0-9]*.[0-9][0-9]* ([Ee] [-]? [0-9][0-9]*)?
string ::= '"' ("\u" [0-9A-Fa-f] [0-9A-Fa-f] [0-9A-Fa-f] [0-9A-Fa-f] | '\' ["\bfnrt] | [^\\"])* '"'
function ::= "function" "(" ((name ("," name)*)?) ")" block
name ::= [a-zA-Z_][a-zA-Z0-9_]*