Implementing Software Solutions
Language Syntax Required for Software Solutions
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.
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.
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.
BNF Symbols
Symbol Meaning
:: = Is defined as
| Indicates choice between elements
< > Non terminal symbol
EBNF Symbols
Symbol Meaning
= Is defined as
| Indicates choice between elements
< > Non terminal symbol
{ } Encloses elements to be repeated
[ ] Encloses optional elements
Railroad Symbols
Symbol Meaning
Predefined element
Fixed element
Path lines
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)
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
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>)
Data Structure Syntax
Arrays So therefore if we typed in our code the
following processes would be incorrect: Dogs (10) cat [1] trees (index)
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.
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
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>}
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)
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.
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>