> ## Documentation Index
> Fetch the complete documentation index at: https://hypotenuse.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# C△ Compiler Error Reference: Syntax, Memory, and Scope

> Complete guide to every error category in the Hypotenuse Compiler — syntax, scope, memory, and file errors — with causes, examples, and debugging tips.

The Hypotenuse Compiler catches errors at multiple stages of compilation: the lexer and parser raise syntax errors, the structurer raises scope errors, and the simulation pass raises memory errors. Error messages also include **personality messages** — randomized flavor text that makes error output more human and easier to spot in a busy terminal. This page covers all error categories with causes and fixes.

## Syntax Errors

The parser raises these errors when the token stream doesn't match expected grammar. Syntax errors always include the offending token and its position in the file.

| Error                                    | Cause                                       | Example             |
| ---------------------------------------- | ------------------------------------------- | ------------------- |
| `Unexpected token at top-level`          | Unknown token outside a function            | `@foo` at file root |
| `Expected IDENTIFIER`                    | Type keyword not followed by a name         | `int 42`            |
| `Expected RPAREN`                        | Unclosed function call or for-loop header   | `foo(1, 2`          |
| `Expected SEMICOLON`                     | Missing `;` at end of statement             | `int x = 5`         |
| `Unexpected end of file`                 | Unclosed `{` block                          | Missing closing `}` |
| `Unexpected token in primary expression` | Invalid token at the start of an expression | `int + 3`           |

<Note>
  The examples above illustrate the most common triggers for each error. The same error message can be raised in other contexts — always read the position information alongside the message to locate the exact problem.
</Note>

## Deprecated Keyword Errors

The lexer raises these errors immediately when it encounters a deprecated C11 keyword. Compilation stops as soon as the keyword is found, before any further parsing takes place.

| Keyword    | Error Message                                                                      |
| ---------- | ---------------------------------------------------------------------------------- |
| `restrict` | `Deprecated keyword used! Please remove or replace the keyword. Found 'RESTRICT'.` |
| `_Bool`    | `Deprecated keyword used! Please remove or replace the keyword. Found 'BOOLEAN'.`  |

<Warning>
  All deprecated keywords — `restrict`, `_Bool`, `_Complex`, and `_Imaginary` — abort compilation immediately. Remove or replace them before re-running the compiler. See the [Keywords reference](/reference/keywords) for the full list.
</Warning>

## Scope Errors

The structurer raises scope errors while building the Callee/Caller/Scope graph. These errors indicate conflicts in how names are declared and used across scopes.

| Error                                     | Cause                                                                    |
| ----------------------------------------- | ------------------------------------------------------------------------ |
| `Child named X already exists in scope Y` | A variable or function named `X` is declared more than once in scope `Y` |

<Note>
  Remember that `for` loop init declarations create their own child scope. A variable declared in a `for` init is not visible in the enclosing function scope, but it will conflict with another variable of the same name declared in the same `for` header.
</Note>

## Memory Errors

The simulation pass raises memory errors during static analysis of pointer lifetimes and function call graphs.

| Error                       | Cause                                                          |
| --------------------------- | -------------------------------------------------------------- |
| `callee not found`          | A function call references a callee that was never defined     |
| `Use after autoremove drop` | Your code accesses a pointer after its `autoremove` free point |
| `Invalid robbery`           | A robbery target is not a valid `autoremove` pointer           |

<Accordion title="Understanding autoremove and robbery">
  When you declare a pointer with `autoremove`, the simulation pass determines the last point in your code where that pointer is used and inserts a `free` call there automatically.

  **Use after autoremove drop** means you reference the pointer again after that auto-inserted free. To fix this, either extend the pointer's lifetime by moving the last use later, or switch to manual `free`.

  **Invalid robbery** means you attempted to "rob" (transfer ownership of) a pointer that was not declared with `autoremove`. Only `autoremove` pointers can be the target of a robbery operation.
</Accordion>

## File Errors

The compiler raises file errors before compilation begins, when it cannot read the input source.

| Error                           | Cause                                                                                |
| ------------------------------- | ------------------------------------------------------------------------------------ |
| `Error: file not found <path>`  | The source file at `<path>` does not exist                                           |
| `Error reading file: <details>` | The OS reported a failure while reading the file — check permissions and disk health |

## Debugging Tips

<Tip>
  Run with `-t` to print the full lexed token stream before any errors reach the parser. This lets you see exactly what the lexer produces and spot unexpected tokens early.
</Tip>

<Tip>
  Run with `-p` to print the full Callee/Caller/Scope graph. Use this when you get a scope error and want to see how the structurer resolved every name in your file.
</Tip>

<Tip>
  Unclosed `{` braces are the single most common cause of `Unexpected end of file` errors. If you see an EOF error, work backwards through your file and check that every opening brace has a matching closing brace.
</Tip>

<Tip>
  Deprecated keywords (`restrict`, `_Bool`, `_Complex`, `_Imaginary`) stop compilation immediately at the lexer stage — no other errors will appear until you remove them. Search your source for these keywords first if compilation exits with a deprecated keyword error.
</Tip>
