JS Eden Syntax Reference

Nick Pope edited this page Dec 17, 2016 · 43 revisions

JS-Eden Grammar

Note that the use of { and } means repeat this bit until it no longer matches. Actual brackets are escaped with a slash. Same goes for | (although currently this is not used in the language).

Expressions

EXPRESSION ->
    TERM with SCOPE
    | TERM :: SCOPE
    | TERM
E -> # | epsilon
E' ->
    ? EXPRESSION : EXPRESSION
    | if EXPRESSION else EXPRESSION
    | epsilon

Terms

These are the binary operators organised by precedence.

TERM -> T { && T | || T }
T -> T' E'
T' -> T'' { < T'' | <= T'' | > T'' | >= T'' | == T'' | != T'' }
T'' -> T''' { + T''' | - T''' | // T'''}
T''' -> T'''' { * T'''' | / T'''' | % T'''' | ^ T''''}
T'''' -> FACTOR E

Factor

Unary operators, literals or a primary.

FACTOR ->
    ( EXPRESSION )
    | - FACTOR
    | number
    | string
    | << observable\n string \nobservable
    | boolean
    | character
    | JAVASCRIPT
    | $ #
    | $ number
    | [ ELIST ]
    | & LVALUE
    | @
    | * FACTOR
    | ! FACTOR
    | PRIMARY

Primary

Right-hand-side use of an observable or backticks, and list indices or function calls.

PRIMARY -> observable {\{ EXPRESSION \}} PRIMARY' | ` EXPRESSION ` PRIMARY'
PRIMARY' ->
    ( ELIST ) PRIMARY''
    | . PRIMARY
    | [ EXPRESSION ] PRIMARY'''
    | epsilon
PRIMARY'' ->
    ( ELIST ) PRIMARY''
    | [ EXPRESSION ] PRIMARY''
    | epsilon
PRIMARY''' ->
    . PRIMARY
    | ( ELIST ) PRIMARY''
    | [ EXPRESSION ] PRIMARY''
    | epsilon

Scope (with)

Specification of scope overrides. Note that only "in" should support RANGE, the other two should be "EXPRESSION" but need to be range for backward compatibility.

SCOPE -> ( SCOPE' ) | SCOPE'
SCOPE' ->
    observable is RANGE SCOPE''
    | observable in RANGE SCOPE''
    | observable = RANGE SCOPE''
SCOPE'' -> , SCOPE' | epsilon
SCOPEPATTERN -> observable {[ EXPRESSION ]}

Expression List

ELIST -> EXPRESSION ELIST' | epsilon
ELIST' -> , EXPRESSION ELIST' | epsilon

Observable List

OLIST -> observable OLIST'
OLIST' -> , observable OLIST' | epsilon

Declarations

PARAS -> para OLIST ; PARAS | epsilon
LOCALS ->
    auto OLIST ; LOCALS
    | local OLIST ; LOCALS
    | epsilon

Proc

ACTION -> observable : OLIST FUNCBODY

If

IF -> ( EXPRESSION ) STATEMENT IF'
IF' -> else STATEMENT | epsilon

While

WHILE -> ( EXPRESSION ) STATEMENT

For

The _OPT means optional.

FOR ->
    ( STATEMENT'_OPT ; EXPRESSION_OPT ; STATEMENT'_OPT ) STATEMENT
    | ( observable in RANGE ) STATEMENT
RANGE ->
    EXPRESSION .. EXPRESSION
    | EXPRESSION
STATEMENT'_OPT -> STATEMENT' | epsilon
EXPRESSION_OPT -> EXPRESSION | epsilon

Do

DO ->
    CODESELECTOR DO';
    | \{ SCRIPT \} DO';
DO' ->
    with SCOPE
    | :: SCOPE
    | epsilon

Selector

Switch

This can only be used inside procs and funcs. Default and break can also be used with this.

SWITCH -> ( EXPRESSION ) \{ SCRIPT \}
CASE -> string : | number : | character :

Func

FUNCTION -> observable FUNCBODY
FUNCBODY -> \{ PARAS LOCALS SCRIPT \}

When

WHEN -> ( EXPRESSION ) STATEMENT WHEN'
WHEN' ->
    with SCOPE
    | :: SCOPE
    | epsilon

Import

IMPORT -> name IMPORT'
IMPORT' -> / IMPORT | IMPORT''
IMPORT'' ->
    @ name IMPORT'''
    | @ number IMPORT'''
    | IMPORT'''
IMPORT''' -> noexec IMPORT''' | force IMPORT''' | create IMPORT''' |
    refresh IMPORT''' | rebase IMPORT''' |
    ;

List Operations

These should be deprecated as not fitting with the language.

INSERT -> LVALUE , EXPRESSION , EXPRESSION ;
DELETE -> LVALUE , EXPRESSION ;
APPEND -> LVALUE , EXPRESSION ;
SHIFT -> LVALUE ;

Wait

Wait cannot be used in a proc or func. The expression must return a number of milliseconds, any other type will fail at run-time.

WAIT -> EXPRESSION ;

Lvalue

Left-hand-side of a statement can be an observable, a pointer dereference or a backticks combined with list indices.

LVALUE ->
    observable LVALUE''
    | * PRIMARY LVALUE'
    | ` EXPRESSION ` LVALUE'
LVALUE' -> [ EXPRESSION ] LVALUE' | . observable LVALUE' | epsilon
LVALUE'' ->
    \{ EXPRESSION \} LVALUE''
    | observable LVALUE''
    | epsilon

Statement

STATEMENT ->
    { SCRIPT } |
    when WHEN |
    proc ACTION |
    func FUNCTION |
    action NAMEDSCRIPT |
    for FOR |
    while WHILE |
    switch SWITCH |
    case CASE |
    default : |
    if IF |
    return EOPT ; |
    continue ; |
    break ; |
    ? CODESELECTOR ; |
    insert INSERT |
    delete DELETE |
    append APPEND |
    shift SHIFT |
    require REQUIRE |
    after AFTER |
    import IMPORT |
    LVALUE STATEMENT'' ; |
    local LOCALS ; |
    auto LOCALS ; |
    wait EXPRESSION ; |
    epsilon
STATEMENT' -> LVALUE STATEMENT''
STATEMENT''	->
    is EXPRESSION |
    in RANGE |
    = EXPRESSION |
    += EXPRESSION |
    -= EXPRESSION |
    /= EXPRESSION |
    *= EXPRESSION |
    ~> [ OLIST ] |
    ++ |
    -- |
    ( ELIST )

Scripts

NAMEDSCRIPT -> observable \{ SCRIPT \}
SCRIPT -> STATEMENT SCRIPT | epsilon
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.