Difference between revisions of "Declaration"

From Mesham
Jump to navigationJump to search
(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…')
 
m (13 revisions imported)
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:Sequential]]
+
== Syntax ==
  
==Syntax==
+
All variables must be declared before they are used. In Mesham one may declare a variable via its value or explicit type.
  
Variable declaration is a key part to any language. In order to declare a variable in Mesham the ''var'' keyword is used.
+
var name;<br>
 +
var name:=[Value];<br>
 +
var name:[Type];<br>
  
var [varname];
+
Where ''name'' is the name of the variable being declared.
var [varname]:=[Value];
 
var [varname]:[Type];
 
  
==Semantics==
+
== 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.
+
The environment will map the identifier to storage location and that variable is now usable. In the case of a value being specified then the compiler will infer the type via type inference either here or when the first assignment takes place.<br><br>
 +
''Note:'' It is not possible to declare a variable with the value ''null'' as this is a special, no value, placer and as such has no type.
  
 +
== Examples ==
  
==Examples==
+
function void main() {
 +
    var a;
 +
    var b:=99;
 +
    a:="hello";
 +
};
  
var a;
+
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.
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.)
+
function void main() {
 +
    var t:Char;
 +
    var z:Char :: allocated[single[on[2]]];
 +
};
 +
 
 +
Variable ''t'' is declared to be a character, without further type information it is also assumed to be on all processes (by default the type Char is allocated to all processes.) Lastly, the variable ''z'' is declared to be of type character, but is allocated only on a single process (process 2.)  
 +
 
 +
''Since: Version 0.41b''
 +
[[Category:sequential]]

Latest revision as of 15:44, 15 April 2019

Syntax

All variables must be declared before they are used. In Mesham one may declare a variable via its value or explicit type.

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

Where name is the name of the variable being declared.

Semantics

The environment will map the identifier to storage location and that variable is now usable. In the case of a value being specified then the compiler will infer the type via type inference either here or when the first assignment takes place.

Note: It is not possible to declare a variable with the value null as this is a special, no value, placer and as such has no type.

Examples

function void main() {
   var a;
   var b:=99;
   a:="hello";
};

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.

function void main() {
   var t:Char;
   var z:Char :: allocated[single[on[2]]];
};

Variable t is declared to be a character, without further type information it is also assumed to be on all processes (by default the type Char is allocated to all processes.) Lastly, the variable z is declared to be of type character, but is allocated only on a single process (process 2.)

Since: Version 0.41b