Errors in a computer program can be classified according to when they are detect
ID: 2247424 • Letter: E
Question
Errors in a computer program can be classified according to when they are detected and, if they are detected at compile time, what part of the compiler detects them. Using your favorite imperative language, give an example or each of the following.
(a) A lexical error, detected by the scanner.
(b) A syntax error, detected by the parser.
(c) A static semantic error, detected by semantic analysis.
(d) A dynamic semantic error, detected by code generated by the compiler.
(e) An error that the compiler can neither catch nor easily generate code to catch (this should be a violation of the language definition, not just a program bug).
Explanation / Answer
Examples are given in C Language:
a) Lexical Error : char a = 'abc'
b) Syntax Error : printf("Error") // No semicolon after printf statement
c)Static Semantic error : " use of an identifier that was never declared"
d) Dynamic Syntax Error : int arr[10]; arr[15] = 0 // Max size delcared is 10 and trying to access 15th location
e) using method name as a variable
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.