I'll try explain EBNF here,
Its basically the text version of Railroad to explain the syntax of a programming language (most HSC questions on EBNF would be to either interpret EBNF or translate given code into EBNF).
I'll run an example and indicate what each symbol means:
===============================================
The given EBNF (courtesy of Course Specifics)
Letter = A | B | C
Digit = 0 | 1 | 2 | 3| 4 | 5
Identifier = <Letter> {<Letter> <Digit>}
LET <Identifier> = <Identifier>
This portion of EBNF explains the syntax of how a variable can be defined.
- LET <Identifier> = <Identifier> simply states the structure in which a variable must be defined with it's value.
- <Identifier> with the <> indicates that this term is specifically defined elsewhere in the EBNF.
- Identifier = <Letter> {<Letter> <Digit>}; the term Identifier without the <> indicates that the term is defined here.
- I'll break down the line of EBNF here:
- The code starting with <Letter> state that the Identifier must start with a Letter term (if you check the Letter definition it must be either the letter A, B or C).
- Then it has non-terminal values in {}. Wavy brackets indicate that the value inside can be repeated 0 or more times.
- If there are no repetitions then the Identifier can comprise of just a single letter.
- If there are repetitions, it must follow the syntax within the brackets, noticeably <Letter> <Digit>, indicating that after the initial letter it must be followed by a letter then a digit.
- If there are more than one repetition the syntax must be followed continually resulting in a pattern of <Letter> <Letter><Digit> <Letter><Digit>...
- Thus a combination of Identifiers can be made with varying length with the repetition.
Some correct/valid definition of Identifier includes A, A
B0, B
A4, A
A0A0 colourcoded the new repetitions of {}.
With these valid definition of Identifier, they can be used in the assignment statement of
LET <Identifier> = <Identifier>, For example;
- LET A = C
- LET AB0 = AA0A0
- LET BA4 = C
I used page 23 of the Course Specifics for the example above.
Please let me know if you still don't get it or if my explanation went on a tangent!