Login

Welcome, Guest. Please login or register.

April 20, 2024, 07:00:59 am

Author Topic: SDD Skills - Metalanguages  (Read 3704 times)  Share 

0 Members and 1 Guest are viewing this topic.

Justin_L

  • MOTM: July 20
  • Moderator
  • Trendsetter
  • *****
  • Posts: 190
  • Respect: +235
SDD Skills - Metalanguages
« on: June 16, 2021, 08:17:59 pm »
+7
SDD Skills - Metalanguages

Welcome to part 3 of the SDD Skills Series – Metalanguages! So what are metalanguages? Before diving into their use, I think it’s helpful to understand where the word comes from. The word itself breaks down into two – “Meta” (meaning self-referential; It refers to itself) and “Language” (Syntax, structure of words and sentences).

This hints strongly at the purpose of metalanguages – simply put, it’s a language used to define other languages.

In the context of this course, we use it to define programming languages – What is a valid statement? How do you check code is syntactically correct? Metalanguages allow us to formally define and verify these ideas, and so becomes an extremely powerful tool when used properly.

Moving onto the practical application of metalanguages, NESA has provided two different ways of representing a metalanguage: Extended Backus-Naur Form (EBNF) and Railroad Diagrams.

You will be required to both interpret and use these metalanguages to meet specifications in an exam, although it's unlikely you’ll be asked to use these in an assessment such as your major work. However, this does mean that many students often go into the final HSC exam with much less practice than in similar skills such as algorithms and system modelling, making it an easy place to lose marks.

Extended Backus-Naur Form (EBNF)
Extended Backus-Naur Form (EBNF) is a system to represent syntax of a language, allowing for the definition of words, statements, and more complex systems. While you may not get much practice with it in class, it is a heavily used in exam questions, which will often ask you to define a programming language using EBNF.

You may also learn about Backus-Naur Form (BNF), but the two systems are similar enough that you should have no trouble switching between them with ease after learning one.

Here is the NESA definition of EBNF:

Sourced from the NESA Software Design and Development Course Specifications

You won’t get this in an exam, so I highly recommend you memorise and practice until you’re comfortable working with unknown problems without referring back to the definition.

Common exam questions include choosing the correct EBNF definition in multiple choice or defining a language from scratch in a short or long answer response. As a result, it’s a good idea that you get comfortable with using EBNF in an exam environment.

Here is the example of one application of EBNF used to define a variable. Let’s say that a variable must start with a letter and can have any combination of letters and digits afterwards.

First, we define a letter as A or B or C, and a Digit as 0 or 1 or 2 or 3 or 4 or 5.

Letter = A | B | C
Digit = 0 | 1 | 2 | 3| 4 | 5


Next, we can define a variable as a letter followed by any number of letters or digits.

Variable = <Letter> {<Letter> | <Digit>}

Notice how we can used previously defined statements as parts in other statements. This allows us to layer and build the syntax of our language.

This allows us to define more complex statements such as the following variable assignment statement:

LET <Variable> = <Variable> | {Digit} | {Letter}

This defines a variable as either another variable, any combination of digits (an integer) or any number of letters (a string). Congratulations, you just modeled a basic programming language!

As mentioned above, this is incredible powerful because it gives us a formal definition of a language, allowing us to verify that a statement is in fact valid. This links in very heavily with the programming languages and compilers topics in the HSC course, and is a taste of the more theoretical side of computer science.

Railroad Diagrams
Another alternative to EBNF is railroad diagrams. This is simply a graphical representation of syntax, and is very straightforward once you’ve gotten the hang of EBNF.

As a general rule of thumb, imagine a train running through the diagram. The train cannot make any sharp turns and cannot go backwards, and so all the possible routes the train can take are valid statement definitions.


Sourced from the NESA Software Design and Development Course Specifications

The only difficulty arises from remembering the specific symbols used. This is often tested in multiple choice questions which give you several variations of the same diagram, as well as occasionally in short and long answer questions which require you to interpret and draw your own diagrams. Railroad diagrams are tested less often and rigorously compared to EBNF, and because of how closely the two are linked, I would recommend spending your time practicing EBNF questions given their increased complexity and mark allocation.

Summary
Hopefully this article was a useful summary or introduction to metalanguages in the HSC Software Design & Development course! If you have time, I would highly recommend checking out the full description of metalanguages in NESA's Software Design and Development Course Specifications, which many of the examples in this article have been adapted from.

If you want to have a go at defining a few more language features or have any questions, feel free to post them below and I’ll provide some feedback!

Otherwise, check out some of the other articles in the SDD Skills Series from the main thread here!
« Last Edit: June 17, 2021, 11:46:45 am by Justin_L »
Да здравствует революция государственного модератора