0% found this document useful (0 votes)
4 views2 pages

Parsing - GATE Computer Science Engineering (CSE) 2024 Mock Test Series - Computer Science Engineering (CSE) PDF Download

The document explains the concept of parsing in compiler design, which follows lexical analysis and checks the syntactical structure of input strings. It describes how a parse tree is constructed using predefined grammar and production rules to determine if an input string is syntactically correct. The document also mentions the complexity of backtracking in parsing and hints at further concepts like FIRST and FOLLOW sets for easier parsing solutions.

Uploaded by

binuchardeve4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Parsing - GATE Computer Science Engineering (CSE) 2024 Mock Test Series - Computer Science Engineering (CSE) PDF Download

The document explains the concept of parsing in compiler design, which follows lexical analysis and checks the syntactical structure of input strings. It describes how a parse tree is constructed using predefined grammar and production rules to determine if an input string is syntactically correct. The document also mentions the complexity of backtracking in parsing and hints at further concepts like FIRST and FOLLOW sets for easier parsing solutions.

Uploaded by

binuchardeve4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

12/19/23, 12:55 PM Parsing - GATE Computer Science Engineering(CSE) 2024 Mock Test Series - Computer Science Engineering (CSE)

ng (CSE) PDF …

Parsing

Introduction to Parsing
When an input string (source code or a program in some language) is given to a compiler, the
compiler processes it in several phases, starting from lexical analysis (scans the input and divides
it into tokens) to target code generation.
Syntax Analysis or Parsing is the second phase, i.e. after lexical analysis. It checks the syntactical
structure of the given input, i.e. whether the given input is in the correct syntax (of the language
in which the input has been written) or not. It does so by building a data structure, called a Parse
tree or Syntax tree. The parse tree is constructed by using the pre-defined Grammar of the
language and the input string. If the given input string can be produced with the help of the
syntax tree (in the derivation process), the input string is found to be in the correct syntax.
The Grammar for a Language consists of Production rules.
Example:
Suppose Production rules for the Grammar of a language are:

S -> cAd
A -> bc|a
And the input string is “cad”.

Now the parser attempts to construct syntax tree from this grammar for the given input string. It
uses the given production rules and applies those as needed to generate the string. To generate
string “cad” it uses the rules as shown in the given diagram:

https://edurev.in/t/83461/2--Parsing--Compiler-Design--GATE 1/2
12/19/23, 12:55 PM Parsing - GATE Computer Science Engineering(CSE) 2024 Mock Test Series - Computer Science Engineering (CSE) PDF …

In the step iii above, the production rule A->bc was not a suitable one to apply (because the string
produced is “cbcd” not “cad”), here the parser needs to backtrack, and apply the next production
rule available with A which is shown in the step iv, and the string “cad” is produced.
Thus, the given input can be produced by the given grammar, therefore the input is correct in
syntax.
But back-track was needed to get the correct syntax tree, which is really a complex process to
implement.
There can be an easier way to solve this, which we shall see in the next article “Concepts of FIRST
and FOLLOW sets in Compiler Design”.

https://edurev.in/t/83461/2--Parsing--Compiler-Design--GATE 2/2

You might also like