Skip to content

Lexical elements and literals

SyntaxDescription
1L / 1U / 1ULInteger suffixes
1.5f / 1.5d / 1.5mFloating-point suffixes
0xFF / 0b1010Hex and binary notation
1_000_000Digit separators
'\n' / '\u0041'Character escapes
"a\tb\"c"String escapes
@"a\b"Verbatim string literals
int 値 = 1;Japanese identifiers
int @class = 1;Identifiers that match a reserved word
// と /* */Comments
using UnityEngine;
using Tsukimi;
public class LexIntegerSuffix : TsukimiBehaviour
{
void Start()
{
long a = 1L;
uint b = 1U;
ulong c = 1UL;
Debug.Log(a + b + (long)c); // => 3
}
}
using UnityEngine;
using Tsukimi;
public class LexFloatSuffix : TsukimiBehaviour
{
void Start()
{
float a = 1.5f;
double b = 1.5d;
decimal c = 1.5m;
Debug.Log(a + b + (double)c); // => 4.5
}
}
using UnityEngine;
using Tsukimi;
public class LexHexAndBinary : TsukimiBehaviour
{
void Start()
{
int a = 0xFF;
int b = 0b1010;
Debug.Log(a + b); // => 265
}
}
using UnityEngine;
using Tsukimi;
public class LexDigitSeparator : TsukimiBehaviour
{
void Start()
{
int a = 1_000_000;
Debug.Log(a); // => 1000000
}
}
using UnityEngine;
using Tsukimi;
public class LexCharEscape : TsukimiBehaviour
{
void Start()
{
char a = '\n';
char b = '\u0041';
Debug.Log(a + b); // => 75
}
}
using UnityEngine;
using Tsukimi;
public class LexStringEscape : TsukimiBehaviour
{
void Start()
{
string s = "a\tb\"c";
Debug.Log(s); // => "a\tb"c"
}
}
using UnityEngine;
using Tsukimi;
public class LexVerbatimString : TsukimiBehaviour
{
void Start()
{
string s = @"a\b";
Debug.Log(s); // => "a\\b"
}
}
using UnityEngine;
using Tsukimi;
public class LexUnicodeIdentifier : TsukimiBehaviour
{
void Start()
{
int= 1;
Debug.Log(値); // => 1
}
}
using UnityEngine;
using Tsukimi;
public class LexKeywordIdentifier : TsukimiBehaviour
{
void Start()
{
int @class = 1;
Debug.Log(@class); // => 1
}
}

// runs to the end of the line; /* */ runs until */. Comments can’t nest — the first */ closes it, and anything after that is read as an expression.

using UnityEngine;
using Tsukimi;
public class LexComment : TsukimiBehaviour
{
void Start()
{
// line comment
/* block comment */
Debug.Log(1); // => 1
}
}