Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Name: Sayed Zahra Abadi Roll No: 19CO07

Course Name: SPCC Lab Sem: VI

Experiment No:- 10 Date: 09/03/2022

Experiment No:- 10

AIM: Case study on What is Parser? How you implement it?

What is Parser?

Parser is the second phase of compilation. The parser takes as its input tokens generated
from the previous phase, i.e., the Lexical Analyzer phase, and groups them in such a way
that their syntax can be recognized.

In computer technology, a parser is a program, usually part of a compiler, that receives


input in the form of sequential source program instructions, interactive online commands,
markup tags, or some other defined interface and breaks them up into parts that can then
be managed by other programming .

It takes input as tokens & converts them into Parse Tree.

Overview of Process
The following example demonstrates the common case of parsing a computer language
with two levels of grammar: lexical and syntactic.

The first stage is the token generation, or lexical analysis, by which the input character
stream is split into meaningful symbols defined by a grammar of regular expressions.

The next stage is parsing or syntactic analysis, which is checking that the tokens form an
allowable expression.

The final phase is semantic parsing or analysis, which is working out the implications of
the expression just validated and taking the appropriate action.

Implementation of Parser
The simplest parser APIs read the entire input file, do some intermediate computation,
and then write the entire output file. (Such as in-memory multi-pass compilers).
Those simple parsers won't work when there isn't enough memory to store the entire
input file or the entire output file. They also won't work for never-ending streams of data
from the real world.

Some alternative API approaches for parsing such data:

1. push parsers that call the registered handlers (callbacks) as soon as the parser
detects relevant tokens in the input stream (such as Expat)
2. pull parsers
3. incremental parsers (such as incremental chart parsers) that, as the text of the file
is edited by a user, does not need to completely re-parse the entire file.
4. Active vs passive parsers

Parsers are widely used in the following technologies:


➢ Java and other programming languages.
➢ HTML and XML.
➢ Interactive data language and object definition language.
➢ Database languages, such as SQL.
➢ Modeling languages, such as virtual reality modeling language.
➢ Scripting languages.
➢ Protocols, such as HTTP and Internet remote function calls.

You might also like