Skip to content

Token and Types

Ty edited this page Mar 22, 2024 · 2 revisions

The first step of the gifscript process (once the input has been read) is tokenization.

Comments

gifscript supports C style and C++ style comments.

/*
  all of this will be ignored by the lexer
  even this line
*/
// And this line too!

Commands

I was originally going to do away with using line ending 'command' characters, but it proved to be difficult when writing the tokenizer.
To end a line, you must put a semicolon ';'

xyz2 123,456,789   // malformed
xyz2 123,456,789;  // correct

Registers

To keep from duplicating information, I'll keep this section simple. A register token is simply the register name.

Modifiers

To also keep from duplicating information, please refer to the register information page for modifier tokens.

Constants

  • Integer -> 123
  • Hexadecimal -> 0x123,x123 (0 prefix is optional)
  • Floating Point -> 123.456f,123.456 (f suffix is optional)

Do know that 123.0f does not equal 123! Internally it is bitcasted and in this example will emit0x42f60000.

Vectors

Vectors are simple, any of the above constants are accepted for each segment of a vector.

  • vec2 -> 123,0x456
  • vec3 -> 123,0x456,789.0f
  • vec4 -> 123,0x456,789.0f,x12
SCISSOR 200,300,100,200 // Pushes a vec4 to SCISSOR
LABEL 0x100,0xFFF // Pushes a vec2 to LABEL

Block Controls

Blocks and packets may be terms used interchangeably. A block is simply a list of commands that form a GIF packet.
There are currently two types of blocks, macro and emitting / drawing blocks. To start and end either type of block, use the curly brackets characters

my_block { // starts block

} // ends block

Macro controls

Macros will be documented on a separate page.
The token for macro controls is simply macro

macro my_macro_block { // Starts macro block

  macro my_second_macro_block; // Nests the second macro block into this one

} // Ends macro block

Identifiers

Used for block or macro names. They are case sensitive strings that must start with a letter or underscore. Underscores (_) are the only special character permitted in an identifier. They are tokenized as such [a-zA-Z_][a-zA-Z0-9_]*

Clone this wiki locally