User Tools

Site Tools


syntax-model

This page provides the details of Dana's syntax model. The source code of a Dana component is parsed in four main passes: first it is tokenised using Dana's standard syntax tokens. Second, the global scope of the source code is parsed, collecting any type definitions and component declarations. This populates the list of known type names. Third, the details of each type definition are then parsed, as are any global-scope constants. And finally, the source code within a component declarations is parsed by recursively converting syntactic constructs such as variable assignment into expressions and statements.

The remainder of this page defines Dana's syntax, operators and constructs in detail.

Syntax tokens:

:< :> . []  ! ~ ++ -- ,

* / % + - << >> & |

:.

<= < >= >

=== !== == !=

&& ||

+= -= *= /= %= <<= >>= &= |= =

:: : ( ) { } ;

Other operators:

implements
clone
new
from
super
asynch
throw
return

Variable qualifiers (not all of these are valid in all scopes):

const
library
static
transfer

Control flow operators:

if
else
for
while
break
mutex

Built-in types:

void
bool
byte
char
int
int1 int2 int4 int8 int16 int32 int64 int128 int256 int512
dec
dec1 dec2 dec4 dec8 dec16 dec32 dec64 dec128 dec256 dec512
Mutex
Thread
Object
Data
TypeField

Built-in global constants:

true
false
null
INT_MAX
this.thread

Component definition keywords:

component
provides
requires
implementation
uses

Type definition keywords:

data
interface
extends

Line ends:

Dana does not use a terminal token to indicate the end of a line of source code. Instead, all source code is compiled into statements by following the syntax rules for detecting an expression. After this, any remaining tokens or fragments that are not statements are flagged as unexpected and compilation fails.

Function declarations:

Within a component, functions are defined either as private local functions or as implementations of a provided interface.

void myFunction(int param)
	{
	
	}

int App:main(AppParam params[])
	{
	
	}

Variable declarations:

A variable is declared by stating a type name followed by a name, which must start with an alphabet character and must not be a keyword. The type name can optionally be preceded by a type qualifier, and the declaration itself can optionally be followed by an initialisation assignment:

[qualifiers] type_name variable [= expression]

String expansion:

When the $ character is present in a string, it is expected that a variable or expression in brackets follows which returns an array of type char.

Expressions:

Dana source code is compiled into expressions using the following rules:

For loop headers

for ( expression_a ; expression_b ; expression_c )

Where expression_a is optional and can be a declaration or an expression; expression_b can be any expression returning a boolean value; and expression_c can by any expression.

Operations

name([param] [, param])

Syntactic constructs

Constructs using syntactic tokens that are upgraded to operations, of the form:

expression token expression

or

expression token

Nested expressions

( expression )

Index expressions

expression [ expression]

Variable accesses

variable_name

Literal accesses

literal_value

Where a literal is an integer or decimal (such as 9 or 9.2), a hex value starting 0x (for example 0xFF), or a string literal of the form “string”.

Dana system calls

dana.call([param])

"this" member calls

this.expression

Object calls

[asynch::] expression.function_call([param])

Member accesses

expression.variable_name

Local function calls

[asynch::] function_call([param])

Array constructions

new type_name[size]

or

new type_name[]([param])

Variable declarations

[variable_qualifier] type_name variable_access

Object constructions

new type_name([param])

Data constructions

new type_name([param])

Clone operations

clone expression

Throw operations

throw expression

syntax-model.txt · Last modified: 2018/02/19 16:16 by barryfp

Page Tools