In: Computer Science
- In general, the occurrence of errors (errors) in a program can be classified in four categories. List and explain, then give an example, of each mistake (error)!
and also
- It is known that: S -> aB | bA A -> a | aS | bAA B -> b | bS | aBB Derivation for the string aaabbabbba Provide a solution for its derivation and syntax analysis.
Please explain it with easy understandable method, because im still in learning phase :). Thanks in advance.
COURSE : Compilation Techniques
The types of errors are classified into 4 categories.
1. Syntax errors
2. Run-time errors
3. Logical errors
4. Latent errors
1. Syntax Errors
Every programming language has different syntax. You have to follow the syntax to successfully compile the program. A syntax error is an error in the source code of a program. If syntax of the program is not correct then compiler gives syntax error. Any violation of rules of programming language results in syntax errors. Syntax error depends on the programming language.
Example: In c , c++ or java if you forgot to put semicolon(;) then it gives error. while in python it gives no error because semicolon is not required in python syntax.
Below is the example of syntax error in c language.
In python if you forgot to put semicolon then it does't give error. See the below example.
So syntax error is totally depends on which programming language you choose.
2. Run-time Errors
Runtime errors are the errors that occur during the execution of the program, after successfully compiling the program. Program successfully compiled so no syntax error is present. Example of runtime error is dividing by zero error. These are not detected by compiler while compilation process. It is difficult to detect and remove runtime errors.
3. Logical Errors
Logical errors are related to the logic of the program. Logical errors are not detected by compiler and cause incorrect results. while executing program expected output is not come and some random output occurs.
In below code for loop runs five times so it should print
Count:
1
Count:
2
Count:
3
Count:
4
Count:
5
but semicolon after for loop is logical error, so it prints only one time.
Correct code after removing logical error shold print like below.
4. Latent Errors
Latent Errors occur only when specific type of data is used.
result = (x * y) / z ;
An error occurs only when z is equal to 0 because that will make remainder zero otherwise it gives correct output. Such errors can be detected only by using all possible combinations of data.
Below is the code when z = 0 so it gives error.
Below is the code when z is not zero. So it gives correct output.