context free grammars languages n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Context-Free Grammars & Languages PowerPoint Presentation
Download Presentation
Context-Free Grammars & Languages

Loading in 2 Seconds...

play fullscreen
1 / 9

Context-Free Grammars & Languages - PowerPoint PPT Presentation


  • 52 Views
  • Uploaded on

Context-Free Grammars & Languages. Example. <program> -> <stmt> <program> | 𝜆 <stmt> -> <assign>|<if>|<while> |… <assign> -> x = 5 | x = 10 <if> -> if (<cond>) <block-stmt> | if (<cond>) <block-stmt> else <block-stmt> | … <cond> -> x == 10 | flag | …

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Context-Free Grammars & Languages' - dillian


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
example
Example

<program> -> <stmt> <program> | 𝜆

<stmt> -> <assign>|<if>|<while> |…

<assign> -> x = 5 | x = 10

<if> -> if (<cond>) <block-stmt> |

if (<cond>) <block-stmt> else <block-stmt> |

<cond> -> x == 10 | flag | …

<block-stmt> -> <stmt><block-stmt> | 𝜆

definition
Definition

A context-free grammar G = (V, , S, P),

where each rule in P has the form A  x

  • A is a variable (A  V)
  • x is a string of variables and terminals (x  (V  )* )
language of cfg
Language of CFG
  • Given a CFG G = (V, , S, P), w ∊ L(G) iff w ∊ * and S =>* w
  • L(G) = { w ∊ * | S =>* w }
context free languages
Context Free Languages

A language L is context-free

iff

There exists a CFG G such that L(G) = L

parsing
Parsing
  • Given a grammar G and string w find derivation of w in G (if it exists.)
derivations and parse trees
Derivations and Parse Trees
  • Left-derivation: Always replace the left-most variable
  • Right-derivation: Always replace the right-most variable
  • Parse tree: Display derivation in a tree
    • Root is start variable
    • Node’s children are symbols of rule used in derivation
ambiguity
Ambiguity
  • A CFG G is ambiguous if
    • There exists w ∊ L(G) such that
    • There is more than 1 parse tree for 2 in G.
  • A language L is inherently ambiguous if
    • For all CFG G, where L(G) = L,
    • G is an ambiguous grammar
tasks
Tasks
  • Remove ambiguity from grammars where possible
  • Efficient creation of parse trees