UNIT -IV. By Mr. M. V. Nikum (B.E.I.T). Software Development Tools. LEX (Lexical Analyzer Generator ) YACC (Yet Another Compiler Compiler )(Parse Generator). LEX. LEX accepts and input specification which consists of two components
ByMr. M. V. Nikum (B.E.I.T)
For an invalid string, the parser issues a diagnostic message reporting the cause & nature of errors in the string
S(S) (SS) ((S)S) (( )S) (( )(S)) (( )((S))) (( )(( )))
This example demonstrates a leftmost derivation : one where we always expand the leftmost non-terminal in the sentential form.
3. Certain grammar specification are not amendable (suitable) to top down analysis. The left-to-left nature of parser would push the parser into an infinite loop of prediction making. To make top-down parsing tensile ,it is necessary to rewrite a grammar so as to eliminate left recursion.
Error detection is restricted to routines which gives defined set of symbols in first position.
Until it is determined that no reduction is possible at current stage of parsing, at this point one new symbol of input string would be admitted for parsing. This is known as Shift action. Due to this nature of parsing , these parses are known as left-to-left parser or shift reduce parser.
EAB EEOE EE+E |
AaEid E*E |
Bb O+|*|/ E/E | id
not operator grammar not operator grammar operator grammar
a <. b b has higher precedence than a
a =· b b has same precedence as a
a .> b b has lower precedence than a
<. with marking the left end,
=· appearing in the interior of the handle, and
.> marking the right hand.
E E+E | E-E | E*E | E/E | E^E | (E) | -E | id
The partial operator-precedence
table for this grammar
$ <. id .> + <. id .> * <. id .> $
$ <. id .> + <. id .> * <. id .> $ E id $ id + id * id $
$ <. + <. id .> * <. id .> $ E id $ E + id * id $
$ <. + <. * <. id .> $ E id $ E + E * id $
$ <. + <. * .> $ E E*E $ E + E * .E $
$ <. + .> $ E E+E $ E + E $
$ $ $ E $