Lexical structure
From Unify Community Wiki
Contents |
Scripts
Javascript for Unity is written inside of one or more script files. Each of these script files contains at least one class definition which must have the same name as the file, e.g. MyJavascript.js will contain the definition for the MyJavascript class. If no class is explicitly created, then Unity will automatically create a class with the correct name, and anything found inside of that file will be made a member of that class.
Tokens
Keywords
- Keyword is an identifier-like sequence of characters that is reserved.
Keyword : one of
- as
- boolean
- break
- byte
- case
- catch
- char
- class
- continue
- default
- do
- double
- else
- enum
- extends
- false
- finally
- float
- for
- function
- if
- import
- in
- instanceof
- int
- long
- new
- null
- #pragma
- private
- protected
- public
- return
- sbyte
- short
- static
- string
- super
- switch
- this
- throw
- true
- try
- typeof
- uint
- ulong
- ushort
- var
- virtual
- void
- while
- yield
Literals
- A literal is a source code representation of a value
Boolean literals
- There are two boolean literal values: true and false
- The type of a boolean literal is boolean
Integer literals
- Integer literals are used for values of type int, uint, long, and ulong
- Integer literals can be of type decimal-integer-literal or hexadecimal-integer-literal
Decimal integer literal
- Decimal integer literals are made of decimal-digits
Decimal digits
- one of:
- 0 1 2 3 4 5 6 7 8 9
Hexadecimal integer literal
- Hexadecimal integer literals are made of hexadecimal-digits
Hexadecimal digits
- one of:
- 0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f
Real literals
- Real literals are used to write values of float and double
- Real literals can be written as:
- decimal-digits . decimal-digits
- . decimal-digits
- decimal-digits
- In real literals, a decimal point must be followed decimal digits. Therefore 1.0 is valid, but 1. is not
String literals
- String literals consist of zero or more characters enclosed in double-quote characters.
- A string literal is of type String
Null literal
- The keyword null makes a null literal of type null
Operators and punctuators
- Operators are used to describe operations between one or more operands. Punctuators are use for grouping and separating.
- punctuators include:
- { } [ ] ( ) . , : ;
- operators include
- + - * / % & | ^ ! ~
- = < > ? ++ -- && || << >>
- == != <= >= += -= *= /= %= &=
- |= ^= <<= >>=