Declaration

From Mesham
Revision as of 15:30, 31 December 2009 by Polas (talk | contribs) (Created page with 'Category:Sequential ==Syntax== Variable declaration is a key part to any language. In order to declare a variable in Mesham the ''var'' keyword is used. var [varname]; va…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search


Syntax

Variable declaration is a key part to any language. In order to declare a variable in Mesham the var keyword is used.

var [varname]; var [varname]:=[Value]; var [varname]:[Type];

Semantics

In the case of a value being specified, the compiler will infer the type via type inference, also making the assumption that the variable is allocated on each process.


Examples

var a; var b:=99; a:="hello"; var t:Char; var z:Char :: allocated[single[on[2]]];

In the code example above, the variable "a" is declared, without any further information the type is infered by its first use (to hold type String.) Variable "b" is declared with value 99, an integer and as such the type is infered to be both Int and allocated on multiple processes. "t" is declared to be a character, without further type information it is also assumed to be on all processes (the type Char is automatically coherced with the type allocated[multiple[]]. Lastly, the variable "z" is declared to be of type character, but is allocated only on a single process (process 2.)