Parser

14
DEFINITION AND SOME KEY POINTS Parser

description

I have made this presentation for my personal work puposes. Just want to have some comments, suggestions, advices from others to make it better. Hope that you guys will help me out

Transcript of Parser

Page 1: Parser

DEFINITION AND SOME KEY POINTS

Parser

Page 2: Parser

Definition

A computer program use just to evaluate scripts according to the respective grammar.

In computer Science, its a text analyzing process to determine if it belongs to a certain language or not.

Mostly used as a part of High-Level-Language

translators(Interpreter or Compiler).

But some Standalone Parsers are available for specific purposes.(for e.g. http://nlp.stanford.edu/software/lex-parser.shtml)

Page 3: Parser

What and How it works?

It first receives input in the form of sequential source program or Stream of characters (String).

Break them into small chunks or parts (tokens).For Example in English Language:

And produces a data-structure that is usually a tree.

He is running to schoolSubject Verb Object

Page 4: Parser

What is not Parsing?

Parser does not evaluate one thing into another. If just change its representation from one form to another.

Parser is not responsible for summarizing or extract the original body of text.

Word Processing Programs also uses a parser to check spelling and grammatical mistakes.

WORD PROCESSING PROGRAMS ALSO USES A PARSER TO CHECK SPELLING AND GRAMMATICAL

MISTAKES.

Page 5: Parser

But What is Compiler ???

Compiler is a Language Translator or a

computer program that translates a Human

understandable instruction set into Computer

understandable form

Or simply, the output of compiler is .exe file,

Object code or RTL(Register Transfer

Language)

Page 6: Parser

Compiler VS Parser

From the previous discussion it can be concluded that: The output of Parser is a Data-Structure that is

useless for the for both Liveware and hardware. But this will be a very useful input for some component

of the compiler.

Whereas, the output of the compiler is understandable and can be executed by Computer hardware

Page 7: Parser

Phases of Compiler

htt

p:/

/ww

w.m

ec.

ac.

in/r

eso

urc

es/

note

s/n

ote

s/co

mp

iler/

Mod

ule

1/i

ntr

o.h

tml

Page 8: Parser

Phases of Compiler

These 3 phases can be called as they are actually parsing the source Program

Page 9: Parser

Lexical Analysis

As the name shows, Its done by Lexical Analyzer.

Reads the characters from the input stream or source program.

Group them in tokens.Each token describe some important element.

CONFUSED….!!!Lets see an exmaple.

Page 10: Parser

Token Example

int a = 10 ;That’s the code for declaring and initializing a variable

“a”.When this LOC passed through t Lexical Box following

thing happens

Each of this term is called as Token.For e.g. “a” is a token of “Identifier type”.The Character Sequence “int” is called as the its

Lexeme.

int a = 10 ;

Identifier Constant

Data Type Assignment Symbol Operator

http://en.wikipedia.org/wiki/Token_(parser)#Token

Page 11: Parser

Can we proceed further OR

Page 12: Parser

Syntax Analyzer

According to many sources, this phase is

actually responsible for Parsing.

So, the input of this phase is the Tokens formed

in the previous phase i.e. Lexical Analysis.

In this phase, the recently formed token

acquire a Hierarchical Data Structure, that’s

called Tree in Computer Science.

Page 13: Parser

Before Moving Further

First Explore this New Buzz Word Tree.

Definition: Its an hierarchical Data Structure

that is also known as the Collection of some

related nodes.

Page 14: Parser

Terminologies

Node is structure that contains some value or condition.

In the tree on right side“2” is a parent node that has two child nodes “7” and “5”.