There are four types of tokens:
Sometimes white space is used to separate the tokens. White space is blank, horizontal tabs, vertical tabs, newlines, formfeeds and comments.
The characters // start a comment. The comment ends at the end-of-line character (\n).
An identifier is a sequence of characters. The first character must be a letter or the special character $. All other characters in the sequence can be letters or digits. Upper- and lower-case characters are not the same.
There are three basic types of constants:
A base ten (decimal) integer-constant is a sequence of digits (example: 4711, 0815)
A base two (binary) integer-constant is a sequence which consists of the characters 0,1 preceded by a 0b or 0B (example: 0b101010)
A base sixteen (hexadecimal) integer-constant is a sequence which consists of the characters 0,1,2..9,a..f,A..F preceded by a 0x or 0X (example: 0xff or 0X2A)
A double-constant is divided in an integer part, a decimal point, a fraction part, a character e or E and a signed integer exponent. The integer and fraction parts are sequences of decimal digits. (examples: 0.5, 0.333E20)
A string-constant starts with a double quote and ends with a double quote (example: "Hello World").
The fraction-constants, complexdouble-constants and the complex-constants are derived from the basic constants.
A fraction-constant is an expression like:
integer-constant / integer-constant
(example: 1/3, 1/10)
A complex-constant is an expression like:
fraction-constant or integer-constant + fraction-constant or integer-constant * I
(examples: I, 3*I, 2+1/3*I )
A complexdouble-constant is an expression like:
double-constant + double-constant * I
(examples: I*1.0, 3.0*I, 2.0+0.333*I )
There are five categories of expressions:
Constants and strings are described in the token-section.
A symbol is an identifier. Symbols can represent symbolic constants (examples: E, Pi, True, False), variables (examples: x, y, z) or functionnames (examples: f, Sin, Cos, Multiply). Symbols can have attributes like (Listable, Flat, Orderless, OneIdentity, HoldFirst, HoldRest, HoldAll). Attributes can be set for a symbol with the function SetAttributes.
A pattern is a symbol with an appended _ (underline character) (examples: x_, y_, i_).
A function is a symbol followed by parantheses containing a possibly empty, comma-separated list of expressions (examples: Sin(0), f(x,y), List()). The list of expressions represent the function arguments.
The following functions can be used for procedural programming:
Break, Continue, Do, If, Return, Switch, While,
The following functions can additionally be written in operator notation:
Operator | Function |
{ } | List |
[ ] | Part |
# | Slot |
symbol-- | Decrement |
--symbol | PreDecrement |
symbol++ | Increment |
++symbol | PreIncrement |
expression! | Factorial |
. | Dot |
^ or ** | Pow |
/ | |
* | Multiply |
- | |
+ | Add |
== | Equal |
!= | Unequal |
< | Less |
<= | LessEqual |
> | Greater |
>= | GreaterEqual |
!expression | Not |
&& | And |
|| | Or |
-> | Rule |
:> | RuleDelayed |
/. | ReplaceAll |
+= | AddTo |
-= | SubtractFrom |
*= | TimesBy |
/= | DivideBy |
& | Lambda |
= | Set |
:= | SetDelayed |
^= | UpSet |
^:= | UpSetDelayed |
; | Statement |