Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Notes  >  The Role of Parser - Syntax Analysis, Computer Science and IT Engineering

The Role of Parser - Syntax Analysis, Computer Science and IT Engineering - Computer Science Engineering (CSE) PDF Download

THE ROLE OF PARSER

The parser or syntactic analyzer obtains a string of tokens from the lexical analyzer and verifies that the string can be generated by the grammar for the source language. It reports any syntax errors in the program. It also recovers from commonly occurring errors so that it can continue processing its input.

The Role of Parser - Syntax Analysis, Computer Science and IT Engineering - Computer Science Engineering (CSE)


Fig. 2.1 Position of parser in comp Functions of the parser :

1. It verifies the structure generated by the tokens based on the grammar.

2. It constructs the parse tree.

3. It reports the errors.

4. It performs error recovery.

 

Issues :

Parser cannot detect errors such as:

1. Variable re-declaration

2. Variable initialization before use

3. Data type mismatch for an operation.

The above issues are handled by Semantic Analysis phase.

 

Syntax error handling :

Programs can contain errors at many different levels. For example :

1. Lexical, such as misspelling an identifier, keyword or operator.

2. Syntactic, such as an arithmetic expression with unbalanced parentheses.

3. Semantic, such as an operator applied to an incompatible operand.

4. Logical, such as an infinitely recursive call.

 

Functions of error handler :

1. It should report the presence of errors clearly and accurately.

2. It should recover from each error quickly enough to be able to detect subsequent errors.

3. It should not significantly slow down the processing of correct programs.

 

Error recovery strategies :

The different strategies that a parse uses to recover from a syntactic error are:

1. Panic mode

2. Phrase level

3. Error productions

4. Global correction

 

Panic mode recovery:

On discovering an error, the parser discards input symbols one at a time until a synchronizing token is found. The synchronizing tokens are usually delimiters, such as semicolon or end. It has the advantage of simplicity and does not go into an infinite loop. When multiple errors in the same statement are rare, this method is quite useful.

 

Phrase level recovery:

On discovering an error, the parser performs local correction on the remaining input that allows it to continue. Example: Insert a missing semicolon or delete an extraneous semicolon etc.

 

Error productions:

The parser is constructed using augmented grammar with error productions. If an error production is used by the parser, appropriate error diagnostics can be generated to indicate the erroneous constructs recognized by the input.

 

Global correction:

Given an incorrect input string x and grammar G, certain algorithms can be used to find a parse tree for a string y, such that the number of insertions, deletions and changes of tokens is as small as possible. However, these methods are in general too costly in terms of time and space.

The document The Role of Parser - Syntax Analysis, Computer Science and IT Engineering - Computer Science Engineering (CSE) is a part of Computer Science Engineering (CSE) category.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
Are you preparing for Computer Science Engineering (CSE) Exam? Then you should check out the best video lectures, notes, free mock test series, crash course and much more provided by EduRev. You also get your detailed analysis and report cards along with 24x7 doubt solving for you to excel in Computer Science Engineering (CSE) exam. So join EduRev now and revolutionise the way you learn!
Sign up for Free Download App for Free

FAQs on The Role of Parser - Syntax Analysis, Computer Science and IT Engineering - Computer Science Engineering (CSE)

1. What is the role of a parser in syntax analysis?
2. How does a parser perform syntax analysis?
Ans. A parser performs syntax analysis by using a formal grammar as a set of rules. It applies these rules to the input program and checks if the program's syntax is valid according to the grammar. The parser uses techniques such as top-down parsing or bottom-up parsing to construct a parse tree or an abstract syntax tree. It recursively applies the grammar rules to break down the program into smaller syntactic units.
3. What is the difference between a parse tree and an abstract syntax tree?
Ans. A parse tree is a hierarchical representation of the syntactic structure of a program according to the rules of a formal grammar. It includes all the grammar symbols and shows the derivation steps used to generate the program. An abstract syntax tree, on the other hand, represents the program's structure in a more abstract and simplified form. It removes the unnecessary details from the parse tree and focuses on the essential elements of the program's syntax.
4. How does a parser handle syntax errors?
Ans. When a parser encounters a syntax error, it reports the error and tries to recover from it. The recovery process can involve techniques such as error correction, error detection, or error reporting. The parser may utilize lookahead symbols or backtrack to find the correct parsing path. The error reporting helps the programmer identify the location and nature of the syntax error so that it can be fixed.
5. What is the significance of syntax analysis in computer science and IT engineering?
Ans. Syntax analysis is a crucial step in the compilation process of programming languages. It ensures that the syntax of a program is correct and follows the rules defined by the language grammar. By performing syntax analysis, compilers can generate efficient code, detect and report errors, and provide meaningful feedback to programmers. It plays a vital role in language processing, code optimization, and overall program correctness.
Download as PDF
Related Searches

Objective type Questions

,

Computer Science and IT Engineering - Computer Science Engineering (CSE)

,

pdf

,

The Role of Parser - Syntax Analysis

,

Exam

,

Sample Paper

,

Free

,

Computer Science and IT Engineering - Computer Science Engineering (CSE)

,

video lectures

,

ppt

,

study material

,

Previous Year Questions with Solutions

,

Summary

,

shortcuts and tricks

,

Important questions

,

Computer Science and IT Engineering - Computer Science Engineering (CSE)

,

The Role of Parser - Syntax Analysis

,

Semester Notes

,

past year papers

,

practice quizzes

,

MCQs

,

Viva Questions

,

The Role of Parser - Syntax Analysis

,

mock tests for examination

,

Extra Questions

;