Professional Documents
Culture Documents
AIM: Case Study On What Is Parser? How You Implement It?
AIM: Case Study On What Is Parser? How You Implement It?
Experiment No:- 10
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.
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.
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