Presentation is loading. Please wait.

Presentation is loading. Please wait.

Define an integer Whole number? Multiple digits? From 0 – 9?

Similar presentations


Presentation on theme: "Define an integer Whole number? Multiple digits? From 0 – 9?"— Presentation transcript:

1 Define an integer Whole number? Multiple digits? From 0 – 9?

2 Programming Techniques

3 Backus-Naur Form or BNF for short 3.3.7 e Explain the need for, and be able to create and apply, BNF (Backus-Naur form) and syntax diagrams Programming Techniques Module Areas

4 BNF Programming Techniques Module Areas Is a way of defining the syntax of a language using context free grammar What on Earth might this mean? Syntax – the definition of what is allowed and the pattern of elements in a language eg In most languages, ‘char’ has a defined format. What is this? Something like: only one in length, can be a-z, A-Z, 0-9, @£$ ……. The point is that the computer needs to know what is allowed and what is not allowed.

5 BNF Task Programming Techniques Module Areas Create a new data type called ‘char2’ You may restrict the range of items that are allowed in this new data type In BNF there is a formal notation that must be used: : : = Means is defined by / consists of Means the syntactic item | Means OR { } Means optional ‘,’ Means AND

6 Programming Techniques Module Areas : : = Means is defined by / consists of Means the syntactic item | Means OR { } Means optional : : = This is saying, ‘the item teacher is defined as’ : : = | ‘,’ This is saying, ‘the item named teacher has the characteristics of being male OR female and is tired’ : : = | ‘,’ ‘,’ {has a home life} The final statement means ………

7 BNF Task revisited Programming Techniques Module Areas Char2 might be defined as: : : = | | | BUT how does the language know what a number is or a letter?

8 BNF Task revisited Programming Techniques Module Areas : : = | | | This is the meta level We need to decompose the elements into the smallest part : : = 0 | 1 | 2 Complete your char2 BNF to include number and letter

9 BNF Task revisited Programming Techniques Module Areas : : = | | | : : = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 : : = a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x| y | z The above BNF provides us with the meta level definition of char2 with finer definitions of the syntactic elements that comprise allowed items Together, the three statements provide a BNF notation OBJECTIVE MET Be able to create and apply, BNF (Backus-Naur form)

10 Explain the need for BNF Programming Techniques Module Areas State two scenarios where BNF might be used Why, if at all, does BNF make programming easier Extension/For Friday Using the playing cards, define a pack of cards using BNF


Download ppt "Define an integer Whole number? Multiple digits? From 0 – 9?"

Similar presentations


Ads by Google