Syntax Error Handling

Common programming errors can occur at many different levels.

• Lexical errors include misspellings of identifiers, keywords, or operators-e.g., the use of an identifier elipseSize instead of ellipseSize and missing quotes around text intended as a string. Misspelling an identifier, keyword, and operator are basically addressed.

• Syntactic errors include misplaced semicolons or extra or missing braces; that is, "{" or " } . " As another example, in C or Java, the appearance of a case statement without an enclosing switch is a syntactic error. (However, this situation is usually allowed by the parser and caught later in the processing, as the compiler attempts to generate code). Unbalanced parenthesis in expressions is handled.

• Semantic errors include type mismatches between operators and operands. An example is a r e t unstatement in a Java method with result type void. Operator on an incompatible operand is an example.

• Logical errors can be anything from incorrect reasoning on the part of the programmer to the use in a C program of the assignment operator = instead of the comparison operator ==. The program containing = may be well formed; however, it may not reflect the programmer's intent. Infinite recursive calls are considered as logical errors.

Usually, error detection and recovery is centered on the syntax analysis phase because of two reasons: Many errors are syntactic in nature and many tokens may disobey the grammatical rules. They can detect the presence of syntactic errors in programs very efficiently. Therefore, parser
should report the presence of errors clearly and accurately. Recover from errors quickly so that it is able to detect subsequent errors. It should not slow down the processing of correct programs. Several parsing methods, LL and LR, detect an error as soon as possible. They have viable-prefix
property, by which they detect error as soon as they see a prefix of the input that is not a prefix of any string in the language.

The error handler in a parser has goals that are simple to state but challenging to realize:
• Report the presence of errors clearly and accurately.
• Recover from each error quickly enough to detect subsequent errors.

• Add minimal overhead to the processing of correct programs.

0 comments