Thinking about grammars - PowerPoint PPT Presentation

1 / 5
About This Presentation
Title:

Thinking about grammars

Description:

A graphical view Each rule ... the node Repeat until P has no non-terminals in a leaf position Select a leaf node L that is a non-terminal Select a grammar tree ... – PowerPoint PPT presentation

Number of Views:101
Avg rating:3.0/5.0
Slides: 6
Provided by: TimF173
Category:

less

Transcript and Presenter's Notes

Title: Thinking about grammars


1
Thinking about grammars
  • Consider an expression language involving
    integers 1, 2 and 3 and the operator
  • These rules make the operator left associative
  • ltegt ltintgt ltegt ltintgt
  • ltintgt 1 2 3
  • Note that using the notation obscures the
    fact that there are really five rules

ltintgt 1 ltintgt 2 ltintgt 3
ltegt ltintgt ltegt ltegt ltintgt
2
A graphical view
  • Each rule is a little tree with a non-terminal as
    its root and children which are non-terminals or
    terminals
  • Heres how we we might visualize the grammar
    using ovals for non-terminals and strings as
    terminals

ltegt ltintgt ltegt ltegtltintgt ltintgt 1 ltintgt
2 ltintgt 3
3
Generating a string parse tree
  • Create a parse tree P consisting ofthe node
  • Repeat until P has no non-terminals in a leaf
    position
  • Select a leaf node L that is a non-terminal
  • Select a grammar tree T that has the same
    non-terminal as its root and make a copy of it
  • Replace the leaf L in P with the copy of T

e
4
1 2 3
  • Heres an example showing the parse tree for
    123

the grammar rules
the parse tree
5
1 2 3
  • Heres an example showing the derivation of 123

e
Write a Comment
User Comments (0)
About PowerShow.com