Meaning Of Parser
Parser – javatpoint
Parser is a compiler that is used to break the data into smaller elements coming from lexical analysis phase.
A parser takes input in the form of sequence of tokens and produces output in the form of parse tree.
Parsing is of two types: top down parsing and bottom up parsing.
Top down paring
The top down parsing is known as recursive parsing or predictive parsing.
Bottom up parsing is used to construct a parse tree for an input string.
In the top down parsing, the parsing starts from the start symbol and transform it into the input symbol.
Parse Tree representation of input string “acdb” is as follows:
Bottom up parsing
Bottom up parsing is also known as shift-reduce parsing.
In the bottom up parsing, the parsing starts with the input symbol and construct the parse tree up to the start symbol by tracing out the rightmost derivations of string in reverse.
Example
Production
Parse Tree representation of input string “id * id” is as follows:
Bottom up parsing is classified in to various parsing. These are as follows:
Shift-Reduce Parsing
Operator Precedence Parsing
Table Driven LR Parsing
LR( 1)
SLR( 1)
CLR ( 1)
LALR( 1)
For Videos Join Our Youtube Channel: Join Now
Feedback
Send your Feedback to [email protected]
Help Others, Please Share
Parsing | Set 1 (Introduction, Ambiguity and Parsers)
In this article we will study about various types of parses. It is one of the most important topic in Compiler from GATE point of view. The working of various parsers will be explained from GATE question solving point of view. Prerequisite – basic knowledge of grammars, parse trees, ambiguity. Role of the parser:In the syntax analysis phase, a compiler verifies whether or not the tokens generated by the lexical analyzer are grouped according to the syntactic rules of the language. This is done by a parser. The parser obtains a string of tokens from the lexical analyzer and verifies that the string can be the grammar for the source language. It detects and reports any syntax errors and produces a parse tree from which intermediate code can be generated. Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry going to types of parsers we will discuss on some ideas about the some important things required for understanding parsing. Context Free Grammars: The syntax of a programming language is described by a context free grammar (CFG). CFG consists of set of terminals, set of non terminals, a start symbol and set of productions. Notation –??? where? is a is a single variable [V]?? (V+T)* Ambiguity A grammar that produces more than one parse tree for some sentence is said to be ambiguous. Eg- consider a grammar S -> aS | Sa | a Now for string aaa we will have 4 parse trees, hence ambiguous For more information refer Removing Left Recursion: A grammar is left recursive if it has a non terminal (variable) S such that their is a derivation S -> Sα | β where α? (V+T)* and β? (V+T)* (sequence of terminals and non terminals that do not start with S) Due to the presence of left recursion some top down parsers enter into infinite loop so we have to eliminate left recursion. Let the productions is of the form A -> Aα1 | Aα2 | Aα3 | ….. | Aαm | β1 | β2 | …. | βn Where no βi begins with an A. then we replace the A-productions by A -> β1 A’ | β2 A’ | ….. | βn A’ A’ -> α1A’ | α2A’ | α3A’| ….. | αmA’ | ε The nonterminal A generates the same strings as before but is no longer left recursive. Let’s look at some example to understand better Removing Left Factoring: A grammar is said to be left factored when it is of the form – A -> αβ1 | αβ2 | αβ3 | …… | αβn | γ i. e the productions start with the same terminal (or set of terminals). On seeing the input α we cannot immediately tell which production to choose to expand A. Left factoring is a grammar transformation that is useful for producing a grammar suitable for predictive or top down parsing. When the choice between two alternative A-productions is not clear, we may be able to rewrite the productions to defer the decision until enough of the input has been seen to make the right choice. For the grammar A -> αβ1 | αβ2 | αβ3 | …… | αβn | γ The equivalent left factored grammar will be – A -> αA’ | γ A’ -> β1 | β2 | β3 | …… | βn The process of deriving the string from the given grammar is known as derivation (parsing). Depending upon how derivation is done we have two kinds of parsers:- Top Down ParserBottom Up ParserWe will be studying the parsers from GATE point of view. Top Down Parser Top down parsing attempts to build the parse tree from root to leaf. Top down parser will start from start symbol and proceeds to string. It follows leftmost derivation. In leftmost derivation, the leftmost non-terminal in each sentential is always chosen. Recursive Descent Parsing S()
{ Choose any S production, S ->X1X2…. ;
for (i = 1 to k)
{
If ( Xi is a non-terminal)
Call procedure Xi();
else if ( Xi equals the current input, increment input)
Else /* error has occurred, backtrack and try another possibility */}}Lets understand it better with an example A recursive descent parsing program consist of a set of procedures, one for each nonterminal. Execution begins with the procedure for the start symbol which halts if its procedure body scans the entire input string. Non Recursive Predictive Parsing: This type if parsing does not require backtracking. Predictive parsers can be constructed for LL(1) grammar, the first ‘L’ stands for scanning the input from left to right, the second ‘L’ stands for leftmost derivation and ‘1’ for using one input symbol lookahead at each step to make parsing action decisions. Before moving on to LL(1) parsers please go through FIRST and FOLLOW Construction of LL(1)predictive parsing table For each production A -> α repeat following steps – Add A -> α under M[A, b] for all b in FIRST(α) If FIRST(α) contains ε then add A -> α under M[A, c] for all c in FOLLOW(A). Size of parsing table = (No. of terminals + 1) * #variables Eg – consider the grammar S -> (L) | a L -> SL’ L’ -> ε | SL’ For any grammar if M have multiple entries than it is not LL(1) grammar Eg – S -> iEtSS’/a S’ ->eS/ε E -> b Important Notes 1. If a grammar contain left factoring then it can not be LL(1)
Eg – S -> aS | a —- both productions go in a
2. If a grammar contain left recursion it can not be LL(1)
Eg – S -> Sa | b
S -> Sa goes to FIRST(S) = b
S -> b goes to b, thus b has 2 entries hence not LL(1)
3. If a grammar is ambiguous then it can not be LL(1)
4. Every regular grammar need not be LL(1) because
regular grammar may contain left factoring, left recursion or ambiguity. We will discuss Bottom Up parser in next article (Set 2). This article is contributed by Parul Sharma
Words in English: Parsing Practice – Rice University
To parse a word means to analyze it into component morphemes. Recall
that morphemes are the smallest units in a language that link a form
with a meaning or function.
Parsing is generally done on complex words that came from Latin and
Greek. (We call such words “Latinate” vocabulary or “Classical”
vocabulary. ) Such words typically show the clearest word structure,
in part because Latin and Greek had many affixes for inflection and
for dervivation,
and (unlike in Germanic) their word structure REQUIRED putting together roots with affixes.
Further, many Classical words were
coined long after the classical period, so the word structure is more
transparent than words from English or French that have been in the
language so long that their morphological structure has become
murky. With many native and nativized words, what were once
separate morphemes have over a long period of time fused together.
For example, the native word stirrup comes from stig ‘climb’ +
rap ‘rope’. The word meant in Old English ‘loop of rope for
placing the foot to climb on a horse’. This word was a compound in Old English, with two separate
morphemes, but now it is a single, unanalyzable morpheme with the
modern meaning ‘device for holding the foot when mounting and riding a
horse. ‘ The whole word now has one morpheme instead of two, and it no
longer refers specifically to rope at all.
The following example words are for parsing practice. For each
morpheme in a word:
2. below it write the morpheme’s
meaning or function. (There may be some parts of the word that are
“linking forms” without any meaning. )
3.
To complete the parse, we state
the actual meaning of the whole word in Modern English. Note that this
meaning may be somewhat indirectly related to the component morphemes.
The ‘e’ in parentheses is only there for spelling reasons–it has no
etymological connection with the word for ‘create’ in Latin. It is
only a prompt to remind us that the morpheme /ate/ is pronounced with
a front mid vowel.
Sample words for parsing
One set of sample words comprises the phonetics terminology for our
class. For these words see Sound terminology.
apteryx hippopotamus megalith
perihelion bilabial eliminate
transliterate seminal iatrogenic
anhydrous biennial apnea
endoscopy supercilious aphelion
inculpate exophthalmic laryngoscope
anemia osculate subcutaneous
luminary amygdala polysemy
pandemic androgynous agenda
memorandum exculpate hippocampus
More sample words for parsing
confluence megalith incarnation
cryptogenic geminate phyllophagous
nyctitropism phototropic phytogenic
aphasia perigee oenophile
formicivorous apterous aliform
arachnophobia apiculture oology
galactic errant errand
Parsing vs. Etymology
Parsing is related to finding the etymology of a word, but it is a
little different because the focus is on word structure, rather than
word history. This has various consequences.
Word structure (for our purposes) includes primarily roots
and affixes. So, many of original bits of the source word, such as
inflectional morphology in the original language, are not relevant to a
parsing.
For example, for hippopotamus, you mind find in a dictionary
etymology that the word comes from Greek hippos ‘horse’
followed by Greek potamos ‘river’. The dictionary etymology
might also indicate that the -us ending comes from Latin (Latin
and Greek were fairly closely related languages, and the Greek noun
inflectional ending -os is historically/etymologically the same
as Latin -us. )
In a parse, we leave out the information about what language the
word parts come from: it is not relevant for this purpose.
Even more important, we also strip the source elements down to their
roots, removing inflectional endings from the original language
that the dictionary etymology included, if they do not survive in the
borrowed word.
The resulting parse:
hippopotamus
hipp + o + potam + us
‘horse’ linker ‘river’ ‘noun inflection’
‘large thick-skinned herbivorous mammal living in and around tropical waters
of Africa’.
For the definition, you have to get close enough to the modern meaning
for someone to understand the thing defined as something distinct from
similar things, but you do not need a very technically precise
definition. For our purposes ‘large African mammal living around
rivers and swamps’ would be good enough.
Important: Definitions
should preserve the part of speech of the word defined. So you would
not define somnambulant as ‘to sleep-walk’, but rather
‘sleep-walking’. It is an adjective, not a verb, so the definition
must be appropriate for an adjective.
As stated above, parsing is generally done on complex words that came
from the classical languages.
The aim in parsing is to find out the structure of the word,
isolating the meaningful elements that recur not only in this word but
in other words, so that
we can learn more of those elements and learn more words that use
them.
Etymology, on the other hand, is more like the story of a word from
the earliest point we can trace, to its modern meaning. Etymology can
be done on any word, because all words have SOME history. Even a novel
creation like googol ‘mathematical term for 10 to the 100th
power’ has an etymology: “Novel creation of amusing-sounding
word by young son of the mathematician who defined it”. But
it wouldn’t make too much sense to try to parse googol,
because it is a simplex word, i. e. it has only one morpheme in it.
In the hippopotamus example, the parse is different from the
etymology, not only because a parse does not include the source
language of loanwords as an etymology does, but also because some
dictionary etymologies break the word down into whole source
words instead of roots, e. g. an etymology might state: “from
L. hippopotamus, from Gr. hippos ‘horse’ +
potamos ‘river’ “. (Dictionary etymologies are heavily
abbreviated and you have to figure out the abbreviations for
the dictionary you use. ) The
-os part of both of the components of the compound was just a
Greek inflectional ending signalling a certain class of masculine noun
with nominative case. It’s not in the parse because it doesn’t show up
in the word today. The -us ending of hippopotamus, on
the other hand, DOES show up in the modern word so we must take
account of it. In fact it is the Latin version of the same Greek
inflectional ending seen in hipp-os. It is enough to just gloss
it as ‘noun inflection’. Later (Ch. 9) we will learn some of the
inflectional categories of Latin and Greek which have ended up in our
English words.
To find the elements relevant to parsing, look in our textbook in
Appendix 1, starting on page 221. These elements are the pure roots
and affixes, without additional morphology, such as inflectional
morphemes that allowed them to be used in whole words in Latin and Greek.
That is what we want to use in parsing: roots and affixes.
© Suzanne Kemmer
Frequently Asked Questions about meaning of parser
What is parser with example?
Parser is a compiler that is used to break the data into smaller elements coming from lexical analysis phase. A parser takes input in the form of sequence of tokens and produces output in the form of parse tree. Parsing is of two types: top down parsing and bottom up parsing.
What is the role of parser?
Role of the parser : … The parser obtains a string of tokens from the lexical analyzer and verifies that the string can be the grammar for the source language. It detects and reports any syntax errors and produces a parse tree from which intermediate code can be generated.Jun 28, 2021
What is word parser?
To parse a word means to analyze it into component morphemes. Recall that morphemes are the smallest units in a language that link a form with a meaning or function. Parsing is generally done on complex words that came from Latin and Greek. … For example, the native word stirrup comes from stig ‘climb’ + rap ‘rope’.