Simple Expressions, Expressions and Statements

Expressions and Statements

The grammatical workhorse of MillScript is the expression. Most contexts expects either expressions or statements - which are merely sequences of semi-colon separated expression. The main practical distinctions are that

  1. an empty sequence is legal but an empty expression is not - use a pair of empty parentheses to denote an expression which delivers no results;
  2. only the last expression in a sequence may return results.
Which contexts require expressions and which require statements has been decided on pragmatic grounds. One one hand we want our syntax to be free of "red tape" and on the other we want some defence against simple typing mistakes. The compromise is that expressions are required when results are required - otherwise statements are allowed. So the conditional-test of an if-expression is an expression but the then & else parts are statements.

Simple expressions

Simple expressions, ones that lack unbracketed infix/postfix operators, are required in a couple of places in MillScript. The most important place is in the attribute of an embedded XML expression, such as
<table border=<em>simple expression</em> />
        

These simple expressions may not contain infix operators - but since any expression can be converted to a simple expression by surrounding it with parentheses, this is not much of a limitation. This means that if you want to compute the border of a table using an arithmetic expression you will want to enclose it in parentheses e.g.

<table border=(x + 1) />