5.3. Parser
Prev | Chapter 5. Internals | Next

## 5.3. Parser

### 5.3.1. Adding tokens

Whatever is changed in POV-Ray™ sources, it is probably that new keywords to the parser have to be added. To call your new keyword as `NEW_KEYWORD_TOKEN` we have to open `parse.h` and find enumerated tokens within `TOKEN_IDS`. Entries in this list are sorted mostly by usage.

    enum TOKEN_IDS
    {
      ABS_TOKEN = 0,
      :
      :
      #ifdef USAGE_WITH_NEW_KEYWORD_PATCH
      NEW_KEYWORD_TOKEN,
      #endif
      :
      :
    };

Once integer identifier is added we have to connect `NEW_KEYWORD_TOKEN` with string for proper parsing. This connection is realized via `Reserved_Words` array in `tokenize.cpp`.

    RESERVED_WORD Reserved_Words[LAST_TOKEN] = {
      {AA_THRESHOLD_TOKEN, "aa_threshold"},
      :
      :
      #ifdef USAGE_WITH_NEW_KEYWORD_PATCH
      {NEW_KEYWORD_TOKEN, "new_keyword" },
      #endif
      :
      :
    };

| Important

Placing of entry into `Reserved_Words` table in `tokenize.cpp` does not require any special order, but adding integer identifier into `TOKEN_IDS` structure in `parse.h` is connected with type of data returned by usage of added keywords. They have to be located in following order:

    enum TOKEN_IDS
    {
      /* tokens to be used when float value is expected from here */
      ABS_TOKEN = 0,
      ATAN_TOKEN,
      :
      FLOAT_FUNCT_TOKEN,
      /* tokens to be used when vector value is expected from here */
      VAXIS_ROTATE_TOKEN,
      :
      VECTOR_FUNCT_TOKEN,
      /* tokens to be used when color value is expected from here */
      ALPHA_TOKEN,
      :
      COLOUR_KEY_TOKEN,
      /* other tokens from here */
      :
      /* LAST_TOKEN has to be the last */
      LAST_TOKEN
    };

Prev | Up | Next
5.2. Binaries | Home | 5.4. Patterns