1. The following set of rules are provided <digit>::= 0|1|2|3|4|5|6|7|8|9| <digitorder>::=<digit>{<digit>} <sign>::= + | - <integer>::=[<sign>]<digitorder> Explain why each of the following integers is valid or invalid using these rules: a. 12345 b. –1001 c. +3 d. 009 e. –22
f. +/- 7 g. 3 + 8 h. –00 i. -1
2. Another language uses the following set of rules: <digit>::= 0|1|2|3|4|5|6|7|8|9 <letter>::= a|b|..|z|A|B|.. |Z <alphanumeric. ::= <letter>|<digit> <identifier>::= <letter><alphanumeric> Explain why each of the following identifiers is valid or invalid using these rules: a. OhNo b. Z1 c. x4 d. a b e. aa f. z?p
- Write these syntax rules in both EBNF and Railroad diagram.
- The letters of the alphabet are divided into vowels (A,E,I,O and U) and consonants (all letters).
- A two-letter word must consist of either a vowel followed by a consonant or a consonant followed by a vowel.
- Create an EBNF representation for the following syntax description:
- A letter is either M or N. A digit is 0, 1 or 2.
- Operations are defined by the symbols & and #.
- An operand is a letter followed by an optional digit.
- A statement consists of an operand followed by one or more operations, one more operand with an asterisk (*) at the end.
- Create a Railroad Diagram for the syntax description above.
- Describe the syntax of a simple arithmetic number sentence (for example 3 + 4 – 5 = 2) using BNF, EBNF or a Railroad Diagram.
HSC Style Questions - Student Activity
|