Add basic var tokens
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
# Variables
|
||||||
|
Variables can be defined in the global scope, in structs and classes, and in functions.
|
||||||
|
|
||||||
|
## Global variables
|
||||||
|
Global variables can be defined as such:
|
||||||
|
|
||||||
|
```c2
|
||||||
|
// Defines a global variable called my_var.
|
||||||
|
int32 my_var;
|
||||||
|
|
||||||
|
// Defines a const variable.
|
||||||
|
const int32 my_var;
|
||||||
|
|
||||||
|
// Defines a global variable whose type is determined automatically.
|
||||||
|
// The value will be determined at runtime.
|
||||||
|
var my_var = 123;
|
||||||
|
|
||||||
|
// Defines a const variable whose type is determined automatically.
|
||||||
|
const my_var = 123;
|
||||||
|
|
||||||
|
// Defines a global variable whose initial value is computed at compile-time.
|
||||||
|
// If it cannot be computed at compile-time, an error is thrown.
|
||||||
|
static my_var = 123;
|
||||||
|
```
|
||||||
@@ -31,6 +31,10 @@ static const KeywordMap keywords[] = {
|
|||||||
{"import", TOKEN_IMPORT},
|
{"import", TOKEN_IMPORT},
|
||||||
{"alias", TOKEN_ALIAS},
|
{"alias", TOKEN_ALIAS},
|
||||||
{"public", TOKEN_PUBLIC},
|
{"public", TOKEN_PUBLIC},
|
||||||
|
{"var", TOKEN_VAR},
|
||||||
|
{"const", TOKEN_CONST},
|
||||||
|
{"static", TOKEN_STATIC},
|
||||||
|
|
||||||
{"void", TOKEN_VOID},
|
{"void", TOKEN_VOID},
|
||||||
{"i8", TOKEN_I8},
|
{"i8", TOKEN_I8},
|
||||||
{"i16", TOKEN_I16},
|
{"i16", TOKEN_I16},
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ typedef enum {
|
|||||||
TOKEN_SEMICOLON,
|
TOKEN_SEMICOLON,
|
||||||
TOKEN_ALIAS,
|
TOKEN_ALIAS,
|
||||||
TOKEN_PUBLIC,
|
TOKEN_PUBLIC,
|
||||||
|
TOKEN_VAR,
|
||||||
|
TOKEN_CONST,
|
||||||
|
TOKEN_STATIC,
|
||||||
|
|
||||||
/* Symbols */
|
/* Symbols */
|
||||||
TOKEN_PARENT_OPEN,
|
TOKEN_PARENT_OPEN,
|
||||||
|
|||||||
Reference in New Issue
Block a user