Parsing

1,989 views

Published on

Published in: Education, Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,989
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
175
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Parsing

  1. 1. Topic:
  2. 2. What is “PARSING”  The term parsing comes from Latin pars meaning part Parsing or syntactic analysis is the process of analyzing a string of symbols, either in natural language or in computer languages according to the rules of a formal grammar.  So Parsing means determining the syntactic structure of an expression
  3. 3. Example of parsing  X=(A-(D*F)) A
  4. 4. Types of Parser  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 Top-down 1) Top-down parser 2) Bottom-up parser Bottom-up
  5. 5. Top-down parsers  Top-down parsing expands a parse tree from the start symbol to the leaves  Always expand the leftmost non-terminal E id + id * id
  6. 6. Top-down parsers Apply E-> E+E E E E id + id * id
  7. 7. Top-down parsers Apply E-> id E E E id + id * id
  8. 8. Top-down parsers Apply E-> E*E E E E E id + id E * id
  9. 9. Top-down parsers Apply E-> id E E E E id + id E * id
  10. 10. Top-down parsers Apply E-> id E E E E id + id E * id
  11. 11. Bottom-up Parser  Start at the leaves and grow toward root     And just as efficient Builds on ideas in top-down parsing Preferred method in practice Also called LR parsing   L means that tokens are read left to right R means that it constructs a rightmost derivation -->
  12. 12. 14 int + (int) + (int) int + ( int ) + ( int )
  13. 13. Example of Bottom-up Parse 15 int + (int) + (int) E + (int) + (int) E int + ( int ) + ( int )
  14. 14. Example of Bottom-up Parse 16 int + (int) + (int) E + (int) + (int) E + (E) + (int) E int E + ( int ) + ( int )
  15. 15. 17 int + (int) + (int) E + (int) + (int) E + (E) + (int) E + (int) E E int E + ( int ) + ( int )
  16. 16. Example of Bottom-up Parse 18 int + (int) + (int) E + (int) + (int) E + (E) + (int) E + (int) E + (E) E E int E E + ( int ) + ( int )
  17. 17. Example of Bottom-up Parse 19 E int + (int) + (int) E + (int) + (int) E + (E) + (int) E + (int) E + (E) E E E int E E + ( int ) + ( int )

×