Types of Common Programming Errors
When a program is written, errors are often unavoidable, no matter how careful the programmer is. These errors may occur during:
- Lexical analysis
- Syntax analysis
- Semantic analysis
- Or even during execution
Below are the four main types of programming errors typically encountered in compiler design:
1. Lexical Errors
These are errors in the spelling or format of tokens during lexical analysis.
Examples:
- Misspelling a keyword or identifier:
- Typing
elipseSize
instead ofellipseSize
- Typing
- Using invalid or missing characters:
"Hello
(missing closing quote for a string)$value
(invalid character in variable name)
Detected by:
Lexical analyzer
2. Syntactic Errors
These errors violate the grammar rules of the programming language.
Examples:
- Missing or extra semicolons, brackets, braces:
- case used without a switch:

3. Semantic Errors
These are meaning-related errors – the code is syntactically correct but makes no sense logically.
Examples:
- Type mismatch:

- Returning a value in a
void
function:

Detected by:
Semantic analyzer
4. Logical Errors
These are hardest to detect because the code is syntactically and semantically valid, but it doesn’t do what the programmer intended.
Examples:
- Using
=
(assignment) instead of==
(comparison):

- Incorrect use of loops or conditions that cause wrong output or infinite loops.
Detected by:
Usually caught only during testing or debugging
Error Detection & Recovery Goals
The compiler’s error handler aims to:
- Clearly report the location and type of error
- Recover quickly so that it can detect more errors later
- Add minimal overhead to the compilation of correct code
Summary Table
Type of Error | Description | Example | Detected By |
---|---|---|---|
Lexical Error | Mistakes in spelling of tokens | elipseSize , "Hello | Lexical Analyzer |
Syntax Error | Structure/grammar violations | Missing ; , case without switch | Parser |
Semantic Error | Type mismatches, invalid returns | return 5; in void method | Semantic Analyzer |
Logical Error | Code runs, but logic is flawed | if (x = 5) instead of x == 5 | Testing/Debugging |