0% found this document useful (0 votes)
73 views10 pages

role of parser

The parser is responsible for analyzing a string of tokens from the lexical analyzer to verify its adherence to the grammar of the source language, generating a parse tree or reporting syntax errors. It operates in conjunction with the lexical analyzer and can employ either top-down or bottom-up methods to build the parse tree. Additionally, the parser handles various types of errors, including lexical, syntactic, semantic, and logical errors during the compilation process.

Uploaded by

anu13papa
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)
73 views10 pages

role of parser

The parser is responsible for analyzing a string of tokens from the lexical analyzer to verify its adherence to the grammar of the source language, generating a parse tree or reporting syntax errors. It operates in conjunction with the lexical analyzer and can employ either top-down or bottom-up methods to build the parse tree. Additionally, the parser handles various types of errors, including lexical, syntactic, semantic, and logical errors during the compilation process.

Uploaded by

anu13papa
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/ 10

Role of the Parser

The parser obtains a string of tokens from the lexical


analyzer, and verifies that the string can be generated by the
grammar for the source language.
The parser returns any syntax error for the source language
Role of Parser
PK EOUCATION
Parser:
" Parsing or syntax analysis is a process which takes the input string
and produces either a parse tree or generates syntax errors.
l institute
" For examplea=a=b+10;
" The above programming statement is first given to lexical analyzer.
" The lexical analyzer will divide it into group of tokens. stitute
" The syntax analyzer takesthe tokens as input and generates
PK
Educational
parse tree.
Role of Parser

PKacational
initute

PEducational
Institute

b 10

Parse tree for a b+ 10 PK


Ed
Role of Parser
PK EDUC
" The parser collects the sufficient number of tokens and builds
a parse tree. Aitute

" Thus, by the parSe tree, parser smartly finds the syntax
yan8 hoonstitut
errors i
" It is also necessary that the parser recover from common
errors so that the task of processing the input can betional
continued.
Institute
Role of Parser
PK EDUCATION
" In the process of compilation, the parser and lexical analyzer
worktogether. hatitute
" When parser requires string of tokens, it invokes lexical analyzer.
. In tur the lexical analyzer supplies tokens to the parser.
" Parser is also known as syntax
D% analyzer.
Educa
ypes of parsers

The task of the parser is essentially to determine if and how


the input can be derived from the start symbol of the
grammar.

This can be done in essentially two ways


a. Top-down parser
b. Bottom-up parser
Top-down parser:

º Top-down parsers build parse trees from the top (root) to


the bottom (leaves).
º Input to the parser is scanned from left to right.
One symbol at a time.
Always expand the leftmost non-terminal
Bottom-up parser:

Bottom-up parsers build parse trees from the leaves and work up to
the root.
Input to the parser is scanned from left to right.
One symbol at a time.
º And just as efficient
The role of parser

regular
expressions errorS

lexical token rest of interm


source parser Parse
program analyzer get next tree front end repres
akeh
symbol "also technically part or
*Uses a grammar to check table parsing
structure of tokens
*produces a parse tree includes augmenting info on
*syntactic erors and recovery tokens in source, type
*recognize correct syntax checking, semantic analysis
report errors
Parsing Responsibilities

Syntax Error Handling.


Lexical: Misspellings
b. Syntactic: Omission, wrong order of tokens
C. Semantic: Incompatible types
d. Logical: Infinite loop / recursive call

You might also like