Reference
Error reference
kemlang-py reports three categories of errors: lexer errors, parse errors, and runtime errors. Each one tells you exactly where the problem is and what went wrong.
Anatomy of an error message
LexerError: unexpected character '?' at line 3, column 8 ParseError: expected '}' after block body at line 7, column 0 RuntimeError: undefined variable 'xyz' at line 5, column 10
Every error includes a type, a human-readable message, and a line:column position pointing to the exact character that caused the problem.
LexerError
Lexer errors happen before parsing even begins. The lexer turns your raw source text into tokens; if it encounters a character or sequence it doesn't understand, it stops with a LexerError.
Unexpected character
LexerError: unexpected character '?' at line 2, column 12
jskkem bhai bhai bol x?2 aavjo bhai
+ - * / % == != < > <= >=), quotes, braces, and parentheses.Unterminated string
LexerError: unterminated string literal starting at line 2, column 10
jskkem bhai bhai bol "hello aavjo bhai
Invalid number literal
LexerError: invalid number literal '3.14.15' at line 3, column 6
3.14 is valid; 3.14.15 is not.ParseError
Parse errors mean the token stream is syntactically invalid - the structure of your program doesn't match the grammar. The parser tells you what it expected and what it found instead.
Missing program header
ParseError: expected 'kem bhai' to start program at line 1, column 0
kem bhai on its own line.jskkem bhai bhai bol "now it works" aavjo bhai
Missing program footer
ParseError: expected 'aavjo bhai' to end program, got EOF at line 5, column 0
aavjo bhai. If you see this error, you probably forgot it or have an unclosed block above.Missing block body brace
ParseError: expected '{' after condition at line 3, column 14jskkem bhai aa x che 5 jo x > 0 bhai bol "positive" aavjo bhai
jo or farvu block must be wrapped in curly braces.jskkem bhai aa x che 5 jo x > 0 { bhai bol "positive" } aavjo bhai
Expected expression
ParseError: expected expression at line 2, column 12
jskkem bhai aa x che aavjo bhai
che keyword must be followed by a value or expression. You cannot declare a variable without initialising it.Missing jya sudhi condition
ParseError: expected 'jya sudhi' after loop body at line 5, column 0
jskkem bhai farvu { bhai bol "hi" } aavjo bhai
farvu loop always needs a jya sudhi condition at the end. Use bhai chhe for an infinite loop that you exit with tame jao.jskkem bhai farvu { bhai bol "hi" } jya sudhi bhai chhe aavjo bhai
RuntimeError
Runtime errors occur while the program is executing - the syntax is valid but something goes wrong at evaluation time. These are the errors you'll encounter most often.
Undefined variable
RuntimeError: undefined variable 'score' at line 4, column 10
jskkem bhai bhai bol score aavjo bhai
aa name che value before using it.Type mismatch
RuntimeError: cannot subtract STRING from INTEGER at line 3, column 12
jskkem bhai aa x che 10 - "five" aavjo bhai
- * / %) only work on numbers. Use + for string concatenation - it auto-converts the other operand.Division by zero
RuntimeError: division by zero at line 3, column 14
jskkem bhai aa x che 10 / 0 aavjo bhai
jo check before dividing.jskkem bhai aa divisor che 0 jo divisor != 0 { bhai bol 10 / divisor } nahi to { bhai bol "cannot divide by zero" } aavjo bhai
Invalid operand for unary minus
RuntimeError: unary minus requires a number at line 2, column 12
-x) only works on integers and floats, not strings or booleans.Input conversion failure
RuntimeError: cannot convert input 'hello' to INTEGER at line 3, column 14
jskkem bhai aa n che bapu tame bolo bhai bol n * 2 aavjo bhai
bapu tame bolo reads input as a string. If you need a number, kemlang-py attempts implicit conversion when the value is used in arithmetic - if the user types something non-numeric, you get this error. Currently there is no built-in parseInt; validate input with a condition and re-prompt if needed.Error exit codes
When a program exits due to an error, the kem process sets an appropriate exit code:
0alwaysProgram ran and exited cleanly1lexer errorsSource could not be tokenized1parse errorsToken stream is syntactically invalid1runtime errorsProgram raised an error during execution2usage errorsWrong CLI command or missing argumentDebugging tips
- ›
Use --trace
kem run file.jsk --trace prints the token stream and AST before running. If the token stream looks wrong, the bug is in the lexer. If the AST looks wrong, the bug is in the parser. If both look right, it's a runtime issue.
- ›
Use kem tokens
kem tokens file.jsk shows exactly how the lexer sees your code - useful for diagnosing unexpected character errors.
- ›
Use kem ast
kem ast file.jsk pretty-prints the AST - useful for checking whether your conditionals and loops parsed as you intended.
- ›
Check line:column
Every error includes a position. Open your file and go to that exact line and column. The error character is usually right there.
- ›
REPL for quick tests
Paste a suspect expression into kem repl to evaluate it interactively without running the whole file.