Errors
This topic is meant to document all possible language errors in Pile
How Errors Work
In Pile, errors are represented like this:
pile: <ERROR>:
at <FILENAME>:<LINE>:
<CODE_LINE>
^
<MESSAGE>
+ <HELP>
<FILENAME>
: The name of the file that the error was thrown.<LINE>
: The line relative to the file that the error was thrown.<CODE_LINE>
: The actual line in the file relative to the file that the error was thrown.<COLUMN>
: The line column relative to the file that the error was thrown.<ERROR>
: The type of error that was thrown.<MESSAGE>
: The error message.<HELP>
: The error help text.
Types of Errors
Token Error
Represented as token error
Unterminated String
Unterminated String is thrown when the lexer finds a string literal without a matching closing delimiter (").
Here's a simple code example:
"I am unterminated
println
Invalid Character
Invalid Character is thrown when the lexer finds an invalid character in a value literal that you write.
Here's a simple code example:
# No cents in Pile
10¢
Illegal Character
Illegal Character is thrown when the lexer finds an illegal character in the file contents.
Here's a simple code example:
# Non-ascii characters are illegal
# vvvvvv
proc привет
"Привет, мир" println
# But inside strings it's fine
end
Parse Error
Represented as parse error
Unexpected Token
Unexpected Token is thrown when the parser finds an unexpected token in the current parsing structure.
Here's a simple code example:
# Parser should expect a valid identifier for procs
proc /notanidentifier end
# ^+++++++++++++++ here
Unexpected EOF
Unexpected EOF (End of File) is very similar to the Unexpected Token error, the only difference is that in place of an unexpected token, the parser finds nothing (the termination of the file).
Here's a simple code example:
proc
# ^ should expect at least something :\
Unterminated Block
Unterminated Block is thrown when the parser doesn't find a mathing end
keyword to close the block.
Here's a simple code example:
proc my_unterminated_procedure
"Hello, Pile" println
# where's the end?
Unmatched Block
Unmatched Block is thrown when the parser does find an end
block termination without the block beginning.
Here's a simple code example:
"hello" "pile" = if
"hello" "pile" swap + println
end
end # bruh
Runtime Error
Represented as runtime error
Stack Underflow
Stack Underflow is thrown when the interpreter tries to execute an operation but the stack doesn't contain enough values on top for the operation.
Here's a simple code example:
1 2 3 + + + trace
# ^ this operation only gets 6, there's no second value :\
Unexpected Type
Unexpected Type is thrown when the interpreter tries to execute an operation but the stack values' datatypes do not match properly.
Here's a simple code example:
"69" 420 = if
# ^ this is not JS please
"bruh" println
end
Invalid Word
Invalid Word is thrown when the interpreter finds an undefined name in any part of the program.
Here's a simple code example:
GIRLFRIEND_PHONE_NUMBER println
Procedure Redefinition
Procedure Redefinition is thrown when the interpreter finds a second definition of a procedure in the program.
Here's a simple code example:
proc again
"Hello, World" println
end
proc again # again!
"Hello, World" println
end
Definition Redefinition
Definition Redefinition is basically the same error as Procedure Redefinition error but for Definitions.
Here's a simple code example:
def PI
3.1415
end
def PI # again!
3.1415
end
Empty Definition
Empty Definition is thrown when the interpreter can't bind a definition to any value. This happens because there's no value on top of the stack after the execution of the definition block.
Here's a simple code example:
def empty
# Nothing here!
end
Unbound Variable
Unbound Variable is thrown when the interpreter can't bind a variable value a value on the stack. This happens because to define a variable, you need the amount of values on the stack corresponding to the variables you are defining.
Here's a simple code example:
# Nothing on the stack!
as no_value let # In this case, it should expect 1 value on the stack
no_value println
end