Difference between revisions of "BNF - Syntax Diagrams"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Syntax Diagrams)
(Syntax Diagrams)
Line 23: Line 23:
 
[[File:Syntaxdiagram.gif]]
 
[[File:Syntaxdiagram.gif]]
  
A another example:
+
so using this diagram, we can see that a digit can be 0-9, and alpha can only be A,B,J, or Z. A stock code must therefore start with one of the alpha characters and then followed by a colon. It can then have any combination of alpha characters or digit characters. Therefore a stock code starting 'AA:' will be invalid, as will a stock code starting '1:'.
 +
 
 +
A another example, this time it is recursive (factor uses exp as part of the diagram):
  
 
[[File:Recursivesyntax.jpg]]
 
[[File:Recursivesyntax.jpg]]
 +
 +
Follow this example from the bottom up, starting at digit and then progress up the diagrams.

Revision as of 14:58, 7 January 2020

Overview

https://www.youtube.com/watch?v=x1gGInKNCRw&list=PLCiOXwirraUAnbNTfWFxkoq5MoIair49B&index=6

BNF

Backus Naur Form is a way of describing the syntax of a value to form a new value.
For example:
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
This declares that <digit> can only be the numbers 0-9, specifically 0 OR 1 OR 2 OR 3 etc.

This notation can also be recursive:
<integer> ::= <digit> | <digit><integer>
This states that an integer can be a digit or a digit followed by another integer.

Quiz

To see if you remember what you have learned about BNF, take this quick test either by yourself, or with friends: https://play.kahoot.it/#/?quizId=cad3ec51-29de-45d6-968d-6a95958553f2

Syntax Diagrams

These are a diagram approach similar to BNF, they also describe the syntax allowed. You are looking for path from left to right, some paths can loop back to allow for multiple digits.

Syntaxdiagram.gif

so using this diagram, we can see that a digit can be 0-9, and alpha can only be A,B,J, or Z. A stock code must therefore start with one of the alpha characters and then followed by a colon. It can then have any combination of alpha characters or digit characters. Therefore a stock code starting 'AA:' will be invalid, as will a stock code starting '1:'.

A another example, this time it is recursive (factor uses exp as part of the diagram):

Recursivesyntax.jpg

Follow this example from the bottom up, starting at digit and then progress up the diagrams.