Abdo Sharaf - Compilers Task 3
Abdo Sharaf - Compilers Task 3
Runtime Error:
• Runtime errors occur during program execution and typically indicate issues such
as division by zero, accessing an index out of range, or using variables before they
are initialized.
• Example:
x=5
y=0
print(x/y)
o Division by zero.
Logical Error:
• Logical errors occur when the code executes without errors but does not produce
the expected result due to incorrect logic or algorithmic mistakes.
• Example:
def calculate_average(a, b):
return (a + b) / 2
print(calculate_average(5, 10)) # gives 7 not 7.5
o The average formula (a + b) / 2 is incorrect; it should be (a + b) / 2.0 to get
the correct floating-point result.
Lexical Error:
• Lexical errors occur during the process of lexing or tokenizing when the lexer
encounters characters or sequences of characters that do not conform to the
syntax rules of the programming language.
• Example: a = @ # not valid in Python