17
Implementing Software Solutions Language Syntax Required for Software Solutions

Sdd Syntax Descriptions

  • Upload
    gavhays

  • View
    1.333

  • Download
    4

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Sdd Syntax Descriptions

Implementing Software Solutions

Language Syntax Required for Software Solutions

Page 2: Sdd Syntax Descriptions

What is a Metalanguage?

Metalanguages provide an understanding of rules implemented into programming languages.

They represent a languages syntax which is used like a checklist when compiling a program to remove errors before execution takes place.

Page 3: Sdd Syntax Descriptions

Why Do We Need Them?

Computers operate in an environmnet full of rules. The use of syntax descriptions enables the computer and programmer to understand the boundaries of its environment.

All data types, data structures and control structures used must have their own set of syntax developed to adhere to.

Page 4: Sdd Syntax Descriptions

Types of Metalanguages?

BNF or EBNF – Which is a text based description of syntax.

Railroad Diagram – Is the graphical based description which is easier to understand.

Page 5: Sdd Syntax Descriptions

BNF Symbols

Symbol Meaning

:: = Is defined as

| Indicates choice between elements

< > Non terminal symbol

Page 6: Sdd Syntax Descriptions

EBNF Symbols

Symbol Meaning

= Is defined as

| Indicates choice between elements

< > Non terminal symbol

{ } Encloses elements to be repeated

[ ] Encloses optional elements

Page 7: Sdd Syntax Descriptions

Railroad Symbols

Symbol Meaning

Predefined element

Fixed element

Path lines

Page 8: Sdd Syntax Descriptions

Activity 1

1. Consider the following EBNF diagram.<Digit> = 1 | 2| 3

<Number> = <Digit> * <Digit>

<Sum> = {<Number>} – {<Number>}

Identify which of the following statements are legal and illegal.

a. Sum = (1 * 2) – (2 * 3)

b. Sum = (1 * 4) – (2 * 3)

c. Sum = (1 * 2) – (2 + 3)

Page 9: Sdd Syntax Descriptions

Activity 1

2. Consider the following Railroad diagram.

Identify which of the following statements are legal and illegal.

a. String = 5a$

b. String = a$

c. String = aa43

d. String = $b56

e. String = aaac11bc$

Letter

Number

Letter $String

Page 10: Sdd Syntax Descriptions

Data Structure Syntax

Arrays The declaration of an array is:

Arrayname(5) Therefore, the syntax description would be:

<Digit> = 0 | 1 | 2 …| 9

<Letter> = a | b | c … |z

<Index> = {<Digit>}

<Arrayname> = {<Letter>}

<Array> = <Arrayname> (<Index>)

Page 11: Sdd Syntax Descriptions

Data Structure Syntax

Arrays So therefore if we typed in our code the

following processes would be incorrect: Dogs (10) cat [1] trees (index)

Page 12: Sdd Syntax Descriptions

Data Structure Syntax

Multidimensional Arrays The declaration of a multidimensional array

is: Arrayname(Digit, Digit)

Using this knowledge create a set syntax descriptions in railroad format for the above multidimensional array.

Page 13: Sdd Syntax Descriptions

Data Structure Syntax

Array of Records Below is an example of a Array of

Records

Name Age

John 11

Ben 12

Create a set of syntax descriptions for an Array of records using EBNF

Page 14: Sdd Syntax Descriptions

Activity 2

1. The following EBNF describes the rules for an array of records.<Digit> = 1 | 2| 3…| 9

<Ucharacter> = A | B | C …..| Z<LCharacter> = a | b | c ……| z<Character> = <UCharacter> | <LCharacter><Boolean> = [Y|N] | [T|F]<Fieldname> = {<Character>}<Fieldentry> = {<Character> | <Digit> | <Boolean>}<Record> = <Fieldname> {<Fieldentry>}<Arrayofrecords> = <Record> {<Record>}

Page 15: Sdd Syntax Descriptions

Activity 2

Identify whether the following are valid or invalid.

Surname First Name Age

Andys Dina 17a)

ID1 Item Cost

12 Ball 17

25 Case 78

Patient Visit Medication

Jenny 25/4/99 T

John 23/4/02 F

b)

c)

Page 16: Sdd Syntax Descriptions

Activity 2

3. Below is a VB statement for opening a file via random access.Open “MYFIL.FIL” For Random AS FileNum Len = Max

Using either EBNF or Railroad create a set of syntax diagrams for this procedure.

Page 17: Sdd Syntax Descriptions

Answer

<Digit> = 1 | 2| 3…| 9

<Ucharacter> = A | B | C …..| Z

<LCharacter> = a | b | c ……| z

<Character> = <UCharacter> | <LCharacter>

<Variable> = {<Character>}

<Filenumber> = {<Digit>}

<Accesstype> = Random | Sequential

<Pathname> = “ {<Character>} . {<Character} “

<Fileaccess> = Open <Pathname> For <Accesstype> As <Filenumber>

Len = <Variable>