Expression Types

Scott Waldron Updated by Scott Waldron

As explained, an expression is something that returns a value. That value can be itself, or it can be a combination of other expressions, or a symbol (variable) lookup.

Literal Values

Literals are the simplest type of expression. They simply return themselves. Dino defines several types of literals – number (floating point and integer), string, char, Boolean (true and false), and null.

'this is a string literal'; // apostrophe marks.
"this is also a string literal"; // quotation marks.
$$this is also a string literal$$; // double-dollar marks.
`a`; // character (char) literal. Note the backticks, not apostrophes.
"a"[0]; // another way of getting a char - first index of a string literal.
3; // integer
0.7 // floating point
true; // or True, TRUE
false; // or False, FALSE
null; // or Null, NULL

These "naked statements" in the examples above are perfectly valid Dino code. Not very useful, except in one specific case - as the return value of an entire script. The final statement in a Dino script can also be a naked expression; that is, an expression without a terminating semicolon. This is useful for quick evaluations that are just a single expression.

// C# test rig code.
[TestMethod]
public void NakedExpressionShouldBeOk()
{
var result = DinoBuilder.Evaluate("3 + 4"); // note no semicolon terminator
Assert.AreEqual(result, 7);
}

[TestMethod]
public void PrintReturnsLastArg()
{
var result = DinoBuilder.Evaluate("print('this', 'is', 'a', 'test')");
Assert.AreEqual(result, "test");
}

Special String ($$)

Dino defines a special string that is delimited with $$ on both ends. So, you can just "$pecial $tring". This string is special because it is evaluated both at compile time (as a statement), and at evaluation time (as an expression). When evaluated at compile time, the compiler will look within these $$ delimiters for a "mini-language", raising the PossibleMiniLanguage event.

The $$ string is also handy for building templates for HTML or XML because you don't need to worry about embedded single or double quotes.

var greeting = $$
<div>
<h1 style="color:red;">Hello, {0}</h1>
</div>
$$;

Variables

Variables return whatever value they contain. A variable must be assigned, after which point it can be used as an expression in other statements and expressions.

var a = 3;
var b = 4;
var c = a + b; // three expressions: a, b, and a + b
c; // naked statement with whatever is in symbol c as the value
var x, y, z = 10; // set multiple symbols to the same value

You can read much more about variables in the main Variables section.

Other Types of Expressions

Most other types of expressions are created by combining simple expressions such as literals and variables. There are infinite ways to combine expressions, most of which involve using operators, which are defined in the next section.

How did we do?

Syntax

Keywords

Contact