Software Design and Development

Home > Software Design and Development > Core > Software Development Cycle > Metalanguages

Metalanguage Answers

  1. Fill in the following table to check whether each example has the correct syntax
Example Data type Legal or illegal Reason
A letter Legal “A” is defined as a letter
7 integer Legal An integer may be defined as a single digit
77 integer Legal An integer may be defined as a digit followed by an integer, which may be… (and so on)
77 signed integer Illegal A signed integer must begin with “+” or “-”
-77 integer Illegal An integer must begin with a digit
-77 signed integer Legal Starts with “-” and followed by an integer
a1 address Illegal “a”  is not defined as a letter
AB6 address Illegal An address is defined as a single letter, followed by an integer
C108 address Legal C108 is a letter followed by a legal integer
D address Illegal An address must contain an integer
D-1 address Illegal An address must contain an integer but not a signed integer

Back to Activity

  1. As the designer of this new language, you want to add the ability to represent an address with more than one letter, followed by more than one digit. Write the BNF statement that would enable this to be done.

    The definitions now read
    <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
    <letter> ::= A | B | C | D | E | F
    <integer> ::= <digit> | <digit> <integer>
    <signed_integer> ::= + <integer> | -<integer>
    <word> ::= <letter> | <letter> <word>
    <address> ::= <word> <integer>

    Back to Activity

  2. Fill in the following table to check whether each example has the correct syntax
Example Data type Legal or illegal Reason
a letter Legal “a” is defined as a letter
t letter Illegal “t” is NOT defined as a letter
b222 identifier Legal Matches the syntax of an identifier
-22 number Legal Matches the syntax of a number
-12.33 number Legal Matches the syntax of a number
21.   Illegal A number must have a at least one digit after a “.”
a:="a2+3 expression Legal Matches the syntax of an expression
b1:="22+12-3 expression Legal Matches the syntax of an expression
b2:="14+2   Illegal 4 is not a digit, if 4 was defined as a digit this would be an legal expression

Back to Activity

  1. Outline whether the above ENBF is equivalent to the syntax defined in the EBNF example 2 above
    No. In the example the sign (+ or -)  is optional, it may or may not be present. In exercise 4, the sign must be there. To make the two versions do the same thing, you would need to add an optional brackets [ ]

    digit = “0” | “1” | “2’ | “3” | “4” | “5” | “6” | “7“ | “8” | “9”
    sign = “+”|”-“
    integer = [sign] digit {digit}

    Back to Activity

  2. Construct EBNF to define an integer in base 2, allowing for a possible sign (+ or -). For example, 1 and 0 are digits, 10, 001, 101, +10, -1111 are all binary integers
    digit = ‘0“ | “1“
    sign = “+”/”-“
    integer = [sign] digit {digit}

    Note: there would be other correct ways to answer this question.

    Back to Activity

  3. Fill in the following table to check whether each selection example has the correct syntax
selection Legal or Illegal Reason
IF(p13>177, CALLA, CALLB) Legal No problem. 177 is a legal integer
IF(a0="p3," CALLA , CALLB) Illegal “="”" is  not defined as a logical operator
If(p13<p12, CALLA CALLB) Illegal Statement must begin with “IF” and "," is missing between CALLA and CALLB

Back to Activity

  1. Convert the follow EBNF syntax to a syntax diagram:

    digit = “1” |” 2” |” 3”
    letter = “a” |” b” |”c”
    operator = “+” |” –“
    identifier = letter {letter | digit}
    number = [“-“] digit {digit} [“.”digit { digit } ]
    expression ="identifier" “:="”" (identifier | number) {operator (identifier| number)}

12 3

4

5

6

Back to Activity

Go To Top

Neals logo | Copyright | Disclaimer | Contact Us | Help