Lexical elements and literals
Forms that compile (11)
Section titled “Forms that compile (11)”| Syntax | Description | Note |
|---|---|---|
1L / 1U / 1UL | Integer suffixes | |
1.5f / 1.5d / 1.5m | Floating-point suffixes | |
0xFF / 0b1010 | Hex and binary notation | |
1_000_000 | Digit 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 | |
// and /* */ | Comments | They can’t be nested: the first */ closes it, so what follows is read as an expression. |
/// <summary>…</summary> | Documentation comments |
Numbers
Section titled “Numbers”Integer suffixes
Section titled “Integer suffixes”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 }}Floating-point suffixes
Section titled “Floating-point suffixes”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 }}Hex and binary notation
Section titled “Hex and binary notation”using UnityEngine;using Tsukimi;
public class LexHexAndBinary : TsukimiBehaviour{ void Start() { int a = 0xFF; int b = 0b1010; Debug.Log(a + b); // => 265 }}Digit separators
Section titled “Digit separators”using UnityEngine;using Tsukimi;
public class LexDigitSeparator : TsukimiBehaviour{ void Start() { int a = 1_000_000; Debug.Log(a); // => 1000000 }}Characters and strings
Section titled “Characters and strings”Character escapes
Section titled “Character escapes”using UnityEngine;using Tsukimi;
public class LexCharEscape : TsukimiBehaviour{ void Start() { char a = '\n'; char b = '\u0041'; Debug.Log(a + b); // => 75 }}String escapes
Section titled “String escapes”using UnityEngine;using Tsukimi;
public class LexStringEscape : TsukimiBehaviour{ void Start() { string s = "a\tb\"c"; Debug.Log(s); // => "a\tb"c" }}Verbatim string literals
Section titled “Verbatim string literals”using UnityEngine;using Tsukimi;
public class LexVerbatimString : TsukimiBehaviour{ void Start() { string s = @"a\b"; Debug.Log(s); // => "a\\b" }}Names and comments
Section titled “Names and comments”Japanese identifiers
Section titled “Japanese identifiers”using UnityEngine;using Tsukimi;
public class LexUnicodeIdentifier : TsukimiBehaviour{ void Start() { int 値 = 1; Debug.Log(値); // => 1 }}Identifiers that match a reserved word
Section titled “Identifiers that match a reserved word”using UnityEngine;using Tsukimi;
public class LexKeywordIdentifier : TsukimiBehaviour{ void Start() { int @class = 1; Debug.Log(@class); // => 1 }}Comments
Section titled “Comments”// runs to the end of the line, and /* */ to the */.
using UnityEngine;using Tsukimi;
public class LexComment : TsukimiBehaviour{ void Start() { // line comment /* block comment */ Debug.Log(1); // => 1 }}Documentation comments
Section titled “Documentation comments”You can write documentation comments, but they appear nowhere.
using UnityEngine;using Tsukimi;
public class DcComment : TsukimiBehaviour{ void Start() { Debug.Log(1); // => 1 }
/// <summary>Description</summary> private int Helper() { return 1; }}