Grammar

  1. program := <function>*

    A program is made up of zero or more functions.

  2. function := function <identifier> ( <identifier>* ) do <statement>* end

    A function begins with the function keyword, an identifier as its name, open parenthesis, zero or more identifiers for its parameters, close parenthesis, the do keyword, zero or more statements, and an end keyword.

  3. statement := <declare-statement> | <input-statement> | <output-statement>> | <set-statement> | <if-statement> | <while-statement> | <run-statement> | <return-statement>

    A statement is either a declare, input, output, set, if, while, run or return statement.

  4. declare-statement := declare <identifier>*;

    The declare statement (used to declare local variables) begins with the 'declare' keyword, followed by zero or more identifiers. Each identifier represents the name of a variable being declared.

  5. input-statement := input <input-data-type> <identifier>;

    The input statement (used to receive input from the program's user through the runtime's standard input) begins with the 'input' keyword, followed by an input data type, then an identifier where the user's input is to be stored.

  6. output-statement := output <output-data-type> <expression>;

    The output statement (used to display output using the runtime's standard output) begins with the 'output' keyword, followed by an output data type, then an expression whose value is to be displayed.

  7. set-statement := set <identifier> = <expression>;

    The set statement (used to assign a value to a variable) begins with with the 'set' keyword, followed by an identifier that identifies the variable where the value is to be stored, then an expression whose value is to be stored in the variable.

  8. if-statement := if <expression> then <statement>* (else <statement>*)? end

    The if statement begins with the keyword 'if', followed by an expression, then the keyword 'then'. This is followed by zero or more statements. Optionally, one can add an else clause by writing the 'else' keyword, followed by zero or more statements. There can only be one else clause. The if statement is terminated by the 'end' keyword.

  9. while-statement := while <expression> do <statement>* end

    The while statement begins with the keyword 'while', followed by an expression, then the keyword do. This is followed by zero or more statements that form the body of the loop. Then you terminate the statement with the 'end' keyword.

  10. run-statement := run <identifier> ( <expression>* );

    The run statement begins with the keyword 'run', followed by an identifier that represents the name of the function that is to be executed, then open parentheses, zero or more expressions as arguments to the function, then lastly, close parentheses and a semi-colon.

  11. return-statement := return <expression>;

    The return statement begins with the keyword return, followed by an expression and a semi-colon.

  12. expression := <unary-expression> | <binary-expression> | <literal-expression> | <symbol-expression> | <call-expression>

    An expression is either a unary, binary, literal, symbol or call expression.

  13. unary-expression := <unary-operator> <expression>

    A unary expression consists of a unary operator followed by an expression.

  14. binary-expression := <expression> <binary-operator> <expression>

    A binary expression consists of an expression, a binary operator, and another expression.

  15. literal-expression := [0-9]+

    A literal expression is a sequence of one or more digits.

  16. symbol-expression := <identifier>

    A symbol expression is simply an identifier.

  17. call-expression := <identifier> ( <expression>* );

    A call expression consists of an identifier followed by open parenthesis, zero or more expressions as arguments to the function being called, then close parenthesis and a semi-colon.

  18. identifier := [A-Za-z_][A-Za-z_0-9]*

    An identifier begins with a letter or underscore, followed by zero or more letters, digits and underscores.

  19. unary-operator := [ ! - ]

    A unary operator is either an exclamation mark or a minus sign.

  20. binary-operator := [ + - * / ^ % & | ]

    A binary operator is one of the following symbols: plus, minus, multiplication, division, caret, percentage, ampersand or pipe.