Extended Backus–Naur form - Paramecium13/LSN GitHub Wiki

LSN uses the "standard" definitions used by many programming languages for: identifiers, string literals, integer literals (support for hexadecimal and binary is not yet implemented), decimal/floating point literals (support for scientific notation is not yet implemented), and whitespace. Comments are C-style. It is insensitive to whitespace...

type = identifier | "bool" | "double" | "int" | "string" |
    ("List" | "Vector"), "<", type, ">";
code file = {file member};
file member = using statement | function | type definition;
using statement = (*current*) "#using", string literal ||
                  (*planned*) "using", string literal, ";";
type definition = struct/record definition | host interface definition |
    script class definition;
struct/record definition = ("struct" | "record"), "{", parameters, "}";
parameters = identifier, ":", type, {identifier, ":", type};
function = function head, body;
function head = "fn", identifier, "(", [parameters], ")", ["->", (type | "()")];

host interface definition = ("host", "interface" | "hostinterface"),
    identifier, "{", {host interface member},
"}";
host interface member = interface function | event;
event = "event", identifier, "(", [parameters], ")", ";";
interface function = function head, ";";

script class definition = ["unique"], ("script", "class" | "script class"),
    identifier, ["<", identifier], "{", {script class member},"}";
script class member = property | field | constructor | script class method |
    event listener | state;
property = "property", identifier, ":", type, ";";
field = "mut", identifier, ":", type, ";";
constructor = "new", "(", [parameters], ")", body;
script class method = "abstract", function head, ";" | ["virtual"] function
event listener = "on", identifier, "(",[parameters],")", body;
state = ("auto"), "state", identifier, "{",
    {state member},
"}";
state member = function | event listener
    (*ToDo: add start block, which runs when entering the state...*);


body = "{", {component}, "}";
component = statement | control structure;
statement = (assignment | reassignment | say | call statement | return statement |
    give statement | goto statement | attach statement | detach statement |
    set state statement | "break" | "next"), ";";
assignment = "let", ["mut"], identifier, "=", expression;
reassignment = (field access | index access), "=", expression;
say = "say", expression, 
    (["with", expression],["as", expression] | ["as", expression], ["with", expression]);
call statement = (function call | method call);
return statement = "return", [expression];
give statement = give item | give gold;
give item = "give", [expression], "item", expression, ["to", expression];
give gold = "give", expression, "gold", ["to", expression];
goto statement = [expression], "goto", expression, ...;
attach statement = "attach", "new", identifier,
    ((attach properties, attach args) | (attach args, attach properties)),
    "to", expression;
attach properties = ["[",[arguments | named arguments],"]"];
attach args = "(",[arguments | named arguments],")";

detach statement = (*not yet implemented*);
set state statement = ("set", "state"| "SetState"), identifier;

control structure = if control | for control | while control | choice control | ...;

choice control = "choice", "{", choice block, {choice block}, "}";
choice block = ["when", expression, ":" (*the condition*)],
    expression (*the text to display*), body;


expression = literal | "(", expression, ")" | function call | method call |
    binary expression | unary expression |
    identifier (*a variable, unique script class, or an in-scope field or property*) |
    field access | index access | constructor expression | "this" | "host" | ...;
literal = string literal | integer literal | boolean literal | float literal;
function call = identifier, ["(", [arguments], ")"];
named argument = identifier, ":", expression;
named arguments = named argument, {named argument};
arguments = expression, {"," expression };
method call = expression, ".", identifier, ["(", [arguments], ")"];
binary expression = expression, binary operator, expression;
binary operator = ...;
unary expression = unary operator, expression, ...
field access = expression, ".", identifier;
index access = expression, "[", expression, "]";
⚠️ **GitHub.com Fallback** ⚠️