BNF and expressive power - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

BNF and expressive power

Description:

var x = 3 mod 2. var y = 3 mod hello' CF and CS grammars ... Type errors. Identifier scoping errors. Can be ... Type rules, scope rules, maybe other rules ... – PowerPoint PPT presentation

Number of Views:58
Avg rating:3.0/5.0
Slides: 8
Provided by: Richard1333
Category:
Tags: bnf | expressive | power | var

less

Transcript and Presenter's Notes

Title: BNF and expressive power


1
BNF and expressive power
  • Richard Connor

2
Language complexity
  • As mentioned before
  • Various classes of language exist
  • Important classes
  • Regular expressions
  • Context-free grammars
  • Context-sensitive grammars

3
Context sensitivity by example
  • var x 3 return( x )
  • var x 3 return( y )
  • Or
  • var x 3 mod 2
  • var y 3 mod hello

4
CF and CS grammars
  • The wrong programs are correct according to a
    context free grammar
  • But this isnt ideal
  • To exclude them, we need a context sensitive
    language definition
  • Ie the correctness of the expression depends on
    its context
  • can we define this in BNF?

5
BNF and context senstive grammars
  • BNF can define context sensitivity
  • lhs of production can have multiple symbols
  • eg
  • ltLgt ltAgt mod ltAgt ltAgt ltAgt
  • ltAgt mod ltAgt ltintgt ltintgt
  • ltAgt ltAgt ltlvalgt ltexpgt
  • ltexpgt ltintgt

6
Classes of BNF definitions
  • Theoretical result only
  • (Not used in practical language definition)
  • Various restrictions can be placed on (pure) BNF
  • Regular expressions Patterns only of the form
  • ltnon terminalgt terminal ltnon terminalsgt
  • Context-free grammars Patterns only of the form
  • lt non terminal gt ltany mix of terminals /
    non-terminalsgt
  • Context-sensitive grammars Patterns including
  • ltany mixgt ltany mixgt

7
Context-sensitive grammars again
  • We do need to define these
  • (almost all real languages require them)
  • To include the concept of
  • Type errors
  • Identifier scoping errors
  • Can be defined in BNF
  • But hard (impossible) to write/read
  • Different techniques are used
  • Context-free grammar description, plus
  • Type rules, scope rules, maybe other rules
  • These narrow the set of strings defined by the CF
    grammar
Write a Comment
User Comments (0)
About PowerShow.com