Difference between revisions of "Literals"

From emotive
Jump to navigation Jump to search
Line 10: Line 10:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
All OTX Core data types (without the Exception type) provide a literal notation term.
+
==List of Literals==
 +
The following table lists all available literals
 +
{| {{TableHeader}}
 +
|- {{TableHeaderRow}}
 +
| '''Data Type''' || '''Literal''' || '''Sample'''
 +
|- {{TableRow1}}
 +
| '''[[Boolean]]''' || <tt><nowiki>{True|False}</nowiki></tt> || <tt>Boolean flag = True;</tt>
 +
|- {{TableRow2}}
 +
| '''[[Integer]]''' || Integer number || <tt>Integer n = 1;<br/>m = n - 1234;</tt>
 +
|- {{TableRow1}}
 +
| '''[[Float]]''' || Floating-point number || <tt>Float n = 1.2;<br/>m = n + 12.345;</tt>
 +
|- {{TableRow2}}
 +
| '''[[String]]''' || Quoted sequence of characters || <tt>String str = "This is a text"<br/>str = StringConcatenate(str, " definded as a literal in OTX.");</tt>
 +
|- {{TableRow1}}
 +
| '''[[ByteField]]''' || Sequence of bytes in hex started with a &amp; || <tt>ByteField bytes1 = &12 34 56 78 90 AB CD EF<br/>ByteField bytes2 = &1234567890ABCDE; // equals &01 23 45 67 89 0A BC DE</tt>
 +
|}

Revision as of 14:51, 15 July 2014

Description

A literal is a notation for representing a fixed value in source code. Almost all programming languages have notations for atomic values such as integers, floating-point numbers, and strings, booleans and characters.

Literals are often used to initialize variables, for example, in the following, '1' is an IntegerLiteral which is assigned to a new created variable 'a' of data type Integer. And the three letter string in "cat" is a StringLiteral, which is assigned to a new created variable 's' of data type String.

Integer a = 1;
String s = "cat";

List of Literals

The following table lists all available literals

Data Type Literal Sample
Boolean {True|False} Boolean flag = True;
Integer Integer number Integer n = 1;
m = n - 1234;
Float Floating-point number Float n = 1.2;
m = n + 12.345;
String Quoted sequence of characters String str = "This is a text"
str = StringConcatenate(str, " definded as a literal in OTX.");
ByteField Sequence of bytes in hex started with a & ByteField bytes1 = &12 34 56 78 90 AB CD EF
ByteField bytes2 = &1234567890ABCDE; // equals &01 23 45 67 89 0A BC DE