Syntax

Scott Waldron Updated by Scott Waldron

Syntax

Dino syntax is simple and expressive. Great care has been taken to make each statement or expression intuitive and easy to remember. Where possible, Dino prefers a plain language way to express statements. Consider the simplest form of the repeat loop.

repeat 10 {
// do something 10 times
}

Statements and Expressions

A valuable skill in making sense of the syntax of any computer language is the ability to distinguish between a statement and an expression. In general terms, a statement "does something but does not return a value", while an expression is "something that is, modifies, or creates a value", usually passing that value to something else. Most computer languages have far more ways to put together expressions, while the number of statements is more limited. Another way to think it is: statements may contain expressions, and expressions may contain expressions, but expressions may not contain statements. So when you type in Dino code, you are always entering at least one statement, and those statements always contain one or more expressions. (There is one exception to this - Dino allows a naked expression as its final statement, so that things like "3+4" can be evaluated without the terminating semicolon. So, you could say any meaningful Dino code must have at least one expression).

Some languages are extremely expressive; JavaScript is probably the most well-known. Nearly everything in JavaScript is an expression. LISP (LISt Processor), affectionately known as (Lost In Silly Parentheses), is entirely expressive - every piece of code is an expression. Dino is expressive too, but compares more closely with Python when it comes to the statement / expression ratio.

A statement in Dino is always terminated with a semicolon (;), or a block ({...}). The following Dino examples show some statements and the expressions within them.

var a = 10; // assignment statement (the literal value 10 is an expression)
a + 3; // "naked" statement with 3 expressions (a, 3, and a + 3)
// A def statement ends with a block instead of a semicolon

def func(a, b){
print("This is a print expression in a def statement");
}

Here is an interesting one - note that it seems to terminate in a block. So why do we need the semicolon? The semicolon is terminating the var assignment statement. We are actually assigning an "anonymous function" (which is an expression that returns itself) to a symbol, "anon".

var anon = (a, b) => {
print("This is an anonymous function def");
};

An if statement can be made up of several blocks.

if a{
print("a was a truthy value");
}
else{
print("a was a falsy value");
}

How did we do?

Concepts

Expression Types

Contact