Skip to content

LRM Expressions

Ayush Jain edited this page Feb 27, 2016 · 8 revisions

Everything in JSJS is an expression. These expressions are composed of identifiers, operators, literals and function calls. A block is a list of several expressions enclosed in curly braces. The entire block is executed in the order in which expressions appear and the value of the last expression is returned. In JSJS, blocks are a part of if-then-else statements and function definitions.

if-then-else

Grammar:

    | if expr then block else block             { If($2, Block($4), Block($6)) }

Example:

if x > y 
then { print(x); x; }
else { print(y); y; }

The curly braces in then and else blocks are required only if the blocks consist of more than one expression and are optional otherwise. They are accordingly handled in the grammar as well.

Clone this wiki locally