Types of Errors in compiler construction

Types of Errors in compiler construction

Types of Errors in compiler construction 

There are two major errors that can occur in  during compiler construction
  1. Syntactic  Error 
  2. Semantic  Error 

Syntactic Error 

Syntax errors are errors in the program text; they may be either lexical or grammatical or an arithmetic expression with unbalanced parentheses, misplaced or mismatched  parentheses.

for example

while (  
    printf("hi); 
}
 In this while has missing ending parentheses  while ( )
and  in printf parentheses one double quotes is missing  (   "hi "  )

lexical error


A lexical error is also types of the syntactic is a mistake in a lexeme, for examples, typing tehn instead of then, or missing off one of the quotes in a literal.

for example

typing     int hero; we  typed her = 5;

Or Misspellings and identifier ,keyword or operator .

Grammatical error


 A grammatical error is a one that violates the (grammatical) rules of the language,

for example if x = 7 y := 4 (missing then). here a keyword is missing .

Semantic errors

These types of errors are much harder and impossible to detect by the compiler or computer.
Semantic errors are mistakes concerning the meaning of a program construct; or an operator which is applied to an incompatible operand so their will be a type mismatched between operator and operand they may be either type errors, logical errors or run-time errors:

for example

int go(){ return 'c'}

in this the go method is return char instead if an integer .

Type errors 

occur when  wrong number of arguments is applied , or  an operator is applied to an argument of the wrong type.

Logical errors 

occur when a badly conceived program is executed and programmer usually say it is a bug but it is not or infinitely recursive call

for example:

typing  if (hero = 1 ) instead of typing if (hero == 1 )

 Run-time errors

 are errors that can be detected only when the program is executed, which is the common known error  for example

dividing 1 by zero .





Comments

Popular posts from this blog

Logical Architecture and UML Package Diagram