Solved exercises on ASN.1 and ABNF

By Jacob Palme, e-mail: jpalme@dsv.su.se, at the research group for CMC (Computer Mediated Communication) in the Department of Computer and Systems Sciences at Stockholm University and KTH.

Original creation date: 6 September 1997. Last revision: 14 March 1999.

These exercises are used in a university course on Internet Application Protocols and Standards.

Exercise 1 (After page 17)

You are to define a protocol for communication between an automatic scale and a packing machine.

The scale measures the weight in grams as a floating point number and the code number of the merchandise as an integer.

Define a data type ScaleReading which the scale can use to report this to the packing machine.

Solution alternative 1 to Exercise 1

ScaleReading ::= [APPLICATION 0] SEQUENCE {       weight Weight,
      itemno Itemno
}

Weight ::= [APPLICATION 1] REAL - - in grams

Itemno ::= [APPLICATION 2] INTEGER

Solution alternative 2 to Exercise 1

ScaleReading ::= [APPLICATION 0] SEQUENCE {
      weight REAL, - - in grams
      itemno INTEGER
}

Warning: The use of the APPLICATION tag is not recommended in the 1994 version of ASN.1. So with the 1994 style of ASN.1:

Solution alternative 3 to Exercise 1

ScaleReading ::= SEQUENCE { weight Weight,
      itemno Itemno
}

Weight ::= REAL - - in grams

Itemno ::= INTEGER

Exercise 2

Some countries use, as an alternative to the metric system, a measurement system based on inches, feet and yeards. Define a data type Measurement which gives one value in this system, and Box which gives the height, length and width of an object in this measurement system. Feet and yards are integers, inches is a decimal value.

Solution alternative 1 to Exercise 2

Box ::= SEQUENCE{
      height Measurement,
      width Measurement,
      length Measurement
}

Measurement ::= SEQUENCE {
      yards INTEGER,
      feet INTEGER,
      inches REAL
}

Exercise 3 (After page 22)

Ändra definitionen av Measurement i Exercise 2 så att feet bara kan ha värdena 0, 1 eller 2 (3 feet är ju en yard), och så att inches är ett heltal mellan 0 och 1199 som anger längden i hundradels tum. (1200 motsvarar ju 12 tum eller en fot).

Change the definition of Measurement in Exercise 2 so that feet can only have the values 0, 1 or 2 (since 3 feet will be a yeard), and so that inches is specified as an integer between 0 and 1199 giving the value in hundreds of an inch (since 1200 or 12 inces will be a foot).

Solution alternative 1 to Exercise 3

Measurement ::= SEQUENCE {
      yards INTEGER,
      feet INTEGER (0 .. 2),
      inches INTEGER (0 .. 1199)
}

Exercise 4

In an opinion poll, made outside the election rooms, every voter is asked to indicate which party they vote for. Allowed values are Labour, Liberals, Conservatives or "other". The age of each voter is also registered as a positive integer above the voting age of 18 years, and the sex is registered. Define a data type to transfer this information from the poll station to a server.

Solution alternative 1 to Exercise 4

Voter ::= SEQUENCE {
      vote Vote,
      age Age,
      male Male
}

Vote ::= INTEGER {
      labour(0),
      liberals (1),
      conservatives (2),
      other (3)
} (0 .. 3)

Age ::= INTEGER ( 18 .. MAX )

Male ::= BOOLEAN

ASN.1 experts say that the following is not permitted

Male ::= [APPLICATION 4] BOOLEAN {
      male (TRUE),
      female (FALSE)
}

Solution alternative 2 to Exercise 4

Voter ::= SEQUENCE {
      vote Vote,
      age Age,
      sex Sex
}

Vote ::= ENUMERATED {
      labour(0),
      liberals (1),
      conservatives (2),
      other (3)
}

Age ::= INTEGER ( 18 .. MAX )

Sex ::= BOOLEAN {
      male (TRUE),
      female (FALSE)
}

Exercise 5

In the local election in Hometown, there are also two local parties, the Hometown party and the Drivers party. Extend solution 1 to exercise 4 to a new datatype HometownVoter where also these two additional parties are allowed.

Solution alternative 1 to Exercise 5

HomeTownVoter ::= SEQUENCE {
      hometownvote Sthvote,
      age Age,
      sex Sex
}

Hometomwnvote ::= INTEGER
      liberals (1),
      conservatives (2),
      other (3),
      hometown-party (4),
      drivers-party (5)
} ( 0 .. 5 )

Note, some people claim that it would be allowed to write:

} ( INCLUDES Vote | 4 | 5 )

as the last line above, but other people claim this is not allowed.

Exercise 6 (After page 29)

In the armed forces, three degrees of secrecy are use: open, secret and high secret. Suggest a suitable datatype to convey the secrecy of a document which is transferred electronically.

Solution alternative 1 to Exercise 6:

Secrecy ::= INTEGER { open(1), secret(2), hsecret(3) } (1..3)

Solution alternative 2 to Exercise 6:

(better according to ASN.1 experts)

Secrecy ::= ENUMERATED { open(1), secret(2), hsecret(3) }

Exercise 7

Given the solution to Exercise 6, assume that a new degree extra high secret is wanted. Define an extended version of the protocol defined in Exercise 6 to allow also this value.

Solution alternative 1 to Exercise 7:

StabSecrecy ::= INTEGER { open(1), secret(2), hsecret(3), ehsecret(4) }
(INCLUDES Secrecy | 4 )

Solution alternative 2 to Exercise 7:

(better according to ASN.1 experts)

StabSecrecy ::= ENUMERATED { open(1), secret(2), hsecret(3), ehsecret(4) }

Exercise 8

Assume that you want to define a pattern to cover a monochrome screen. Each pixel on the screen can be either black or white. The pattern is made by repeating a rectangle of N times M pixels over the whole screen. Examples of possible patterns are:

Base

Example of screen segment

Specify an ASN.1 data type which you can use to describe different such patterns.

Solution alternative 1 to Exercise 8

Pattern ::= SEQUENCE {
      height INTEGER,
      width INTEGER,
      pattern BIT STRING - - row by row
}

Solution alternative 2 to Exercise 8

Row ::= BIT STRING

Pattern ::= SEQUENCE {
      height INTEGER,
      width INTEGER,
      pattern SEQUENCE OF Row
}

Exercise 9

A store holds paper in the formats A3, A4, A5 and A6. A user wants to know if sheets are available in each of these four formats. Specify a data type to report this to the user.

Solution alternative 1 to Exercise 9

InStore ::= BIT STRING {
      a3 (0),
      a4 (1),
      a5 (2),
      a6 (3)
} (SIZE(4))

Exercise 10 (After page 35)

The X.400 standard specifies that a name can consist of several subfields. One of the subfields is called OrganizationName and can have as value between 1 and 64 characters from the character se PrintableString. Suggest a definition of this in ASN.1.

Solution alternative 1 to Exercise 10 (taken from X.411, 1998 version)

ub-organization-name-length INTEGER ::= 64

OrganizationName ::= PrintableString
(SIZE (1 .. ub-organization-name-length))

Here is another solution, using new constructs from the 1994 version of ASN.1:

Name {INTEGER : name-length} ::= PrintableString (Size(1..name-length))

OrganizationDirectorName ::= Name {32}

Exercise 11 (After page 43)

In a protocol for transferring personal data between two computers, a social security number is transferred. This number consists of only digits, blanks and dashes. Name (not split into first name and surname, max 40 characters) can also be transferred if known, and an estimated yearly income can be transferred if known. Both of these values are optional, only the social security number is mandatory. Specify using the SET construct of ASN.1 a datatype to transfer this information.

Solution alternative 1 to Exercise 11

PersonRecord ::= SET {
      pnumber Pnumber,
      name Nametype OPTIONAL,
      income Incometype OPTIONAL
}

Pnumber1 ::= [APPLICATION 1] PrintableString
(FROM ("0" | "1" | "2" | "3" | "4"|"5" | "6" | "7" | "8" | "9"| "-" | " "))

Pnumber ::= Pnumber1 (SIZE (13))

Nametype ::= GeneralString (SIZE (1 .. 40))

Incometype ::= INTEGER (0 .. MAX)

Solution alternative 2 to Exercise 11

PersonRecord ::= SET {
      pnumber Pnumber,
      name Nametype OPTIONAL,
      income Incometype OPTIONAL
}

Pnumber1 ::= PrintableString (FROM ("0" | "1" | "2" | "3" | "4"|"5" | "6" | "7" | "8" | "9"| "-" | " "))

Pnumber ::= Pnumber1 (SIZE (13))

Nametype ::= GeneralString (SIZE (1 .. 40))

Incometype ::= INTEGER (0 .. MAX)

Solution alternative 3 to Exercise 11

Pnumber1 ::= PrintableString (FROM ("0" | "1" | "2" | "3" | "4"|"5" | "6" | "7" | "8" | "9"| "-" | " "))

PersonRecord ::= [APPLICATION 0] SET {
      pnumber Pnumber1 (SIZE (13))
      name GeneralString (SIZE (1 .. 40)) OPTIONAL,
      income INTEGER (0 .. MAX) OPTIONAL
}

Note: With the 1994 version of ASN.1, you might also write:

Pnumber1 ::= PrintableString (FROM ("0" .. "9" | "-" | " "))

Exercise 12

Assume that a name is to be transferred as two fields, one for given name and one for surname. How can the solution to Exercise 11 be changed to suit this case?

Solution alternative 1 to Exercise 12

PersonRecord ::= SET {
      pnumber Pnumber,
      gname GNametype OPTIONAL,
      sname SNametype OPTIONAL,
      Income Incometype OPTIONAL
}

Pnumber1 ::= PrintableString
      (FROM ("0" | "1" | "2" | "3" | "4"|"5" | "6" | "7" | "8" | "9"| "-" | " "))

Pnumber ::= Pnumber1 (SIZE (13))

GNametype ::= [APPLICATION 0] GeneralString (SIZE (1 .. 40))

SNametype ::= GeneralString (SIZE (1 .. 40))

Incometype ::= INTEGER (0 .. MAX)

Solution alternative 2 to Exercise 12

PersonRecord ::= SET {
      pnumber Pnumber,
      name Nametype OPTIONAL,
      income Incometype OPTIONAL
}

Pnumber1 ::= PrintableString
(FROM ("0" | "1" | "2" | "3" | "4"|"5" | "6" | "7" | "8" | "9"| "-" | " "))

Pnumber ::= Pnumber1 (SIZE (13))

Nametype ::= SEQUENCE {
      sName GeneralString (SIZE (1 .. 40)),
      gName GeneralString (SIZE(1 .. 40))
}

Incometype ::= [APPLICATION 3] INTEGER (0 .. MAX)

Question: Why is the solution below not correct?

PersonRecord ::= [APPLICATION 0] SET {
      pnumber Pnumber,
      gname Nametype OPTIONAL,
      sname Nametype OPTIONAL,
      income Incometype OPTIONAL
}

Pnumber1 ::= PrintableString
(FROM ("0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"| "-" | " "))

Pnumber ::= Pnumber1 (SIZE (13))

Nametype ::= GeneralString (SIZE (1 .. 40))

Incometype ::= INTEGER (0 .. MAX)

Answer: The receiving computers cannot know if a name with only one componet is only a gname or only a sname.

Exercise 13 (After page 43B)

Given the ASN.1-type:

XYCoordinate ::= SEQUENCE {
      x REAL,
      y REAL
}

Define a subtype which only allows values in the positive quadrant (where both x and y are >= 0).

Solution alternative 1 to Exercise 13

PositiveCoordinate ::= XYCoordinate
( WITH COMPONENTS {
      x (0 .. MAX)
      y (0 .. MAX)
}
)

Exercise 14

Given the ASN.1 type:

Message ::= SET {
      author Name OPTIONAL,
      textbody IA5String }

Define a subtype to this, called AnonymousMessage, in which no author is specified.

Solution alternative 1 to Exercise 14

AnonymousMessage ::= Message
      ( WITH COMPONENTS {... , author ABSENT }
)

Solution alternative 2 to Exercise 14

AnonymousMessage ::= Message
      ( WITH COMPONENTS {
            author ABSENT,
            textbody }
)

Exercise 15

Define a datatype FullName which consists of three elements in given order: Given name, Initials and Surname. Given name and Initials are optional, but Surname is mandatory.

Solution alternative 1 to Exercise 15

FullName ::= SEQUENCE {
      givenName [0] IA5String OPTIONAL,
      initials [1] IA5String OPTIONAL,
      surname [2] IA5STring
}

Question: Can the tags in the solution above be removed?

Answer: Yes if you have automatic tagging set, otherwise no, since the elements must have different tags to separate them. If the first two elements had not been OPTIONAL, then the tags would not have been required, since then the elements could be separated by their order in the SEQUENCE.

Exercise 16 (After page 45)

Define a data type BasicFamily consisting of 0 or 1 husband, 0 or 1 wife and 0, 1 or more children. Each of these components are specified as an IA5String.

Solution alternative 1 to Exercise 16

BasicFamily ::= SEQUENCE {
      husband [0] IA5String OPTIONAL,
      wife [1] IA5String OPTIONAL,
      children [2] SEQUENCE OF IA5String OPTIONAL
}

With automatic tagging, the tags above can be removed.

Question: Is SEQUENCE OF or SET OF best in this exercise?

Answer: If you want to indicate the order of the children, SEQUENCE OF os better.

Exercise 17

Define a datatype ChildLessFamily, based on BasicFamily from Exercise 16.

Solution alternative 1 to Exercise 17

ChildLessFamily ::= BasicFamily
( WITH COMPONENTS {
      ... , children ABSENT
}
)

Exercise 18 (After page 49)

Given the data types Aircraft, Ship, Train and MotorCar, define a datatype Vessel whose value can be any of these datatypes.

Solution alternative 1 to Exercise 18

Vessel ::= CHOICE {
      aircraft Aircraft,
      ship Ship,
      train Train,
      motorcar MotorCar
}

Exercise 19

What is the difference between the data type:

NameListA ::= CHOICE {
      ia5 [0] SEQUENCE OF IA5String,
      gs [1] SEQUENCE OF GeneralString
}

and the data type:

NamelistB ::= SEQUENCE OF CHOICE {
      ia5 [0] IA5String,
      gs [1] GeneralString
}

How is it in both alternatives above possible to define a new data type GeneralNameList which only can contain a GeneralString element?

Solution alternative 1 to Exercise 19

GeneralNameListA ::= gs < NameListA

GeneralNameListB ::= NamelistB
      ( WITH COMPONENT
      (WITH COMPONENTS {gs} )
)

Solution alternative 2 to Exercise 19

GeneralNameListA ::= NameListA ( WITH COMPONENTS {gs} )

GeneralNameListB ::= NamelistB
      ( WITH COMPONENT
      (WITH COMPONENTS {gs} )
)

Exercise 20

A society allows two kinds votes:

(a) The voters can select one and only one of 1 .. N alternatives. The alternative which gets the most total votes wins.

(b) The voters can indicate a score of between 0 and 10 for each of the choices 1 .. N. The choice which gets highest total score wins.

Specify an ASN.1 data type which can be used to report the votings of a person to the vote collection agent, and which can be used for both kinds of votes. The name of the voter shall be included in the report as an IA5String.

Solution alternative 1 to Exercise 20

Vote ::= SEQUENCE {
      voterName IA5String,
      votevalue CHOICE {
            chosenAlternative AlternativeNumber,
            setvalue SET OF SEQUENCE {
                  alternative AlternativeNumber,
                  score INTEGER ( 0 .. 10 )
            }
      }
}

Solution alternative 2 to Exercise 20

(This solution assumes that the voter always specifieds the choices in a given order, so that the number of the choices need not be sent.)

Vote ::= SEQUENCE {
      voterName IA5String,
      votevalue CHOICE {
            chosenAlternative AlternativeNumber,
            sequencevalue SEQUENCE OF
            INTEGER ( 0 .. 10 )
      }
}

Exercise 21 (After page 58)

Assume an ASN.1-module which looks like this:

WeatherReporting {2 6 6 247 1} DEFINITIONS EXPLICIT TAGS ::=

BEGIN

WeatherReport ::= SEQUENCE {
      height [0] IMPLICIT REAL,
      weather [1] IMPLICIT Wrecord
}

Wrecord ::= [APPLICATION 3] SEQUENCE {
      temp Temperature,
      moist Moisture
      wspeed [0] Windspeed OPTIONAL
}

Temperature ::= [APPLICATION 0] IMPLICIT REAL

Moisture ::= [APPLICATION 1] REAL

Windspeed ::= [APPLICATION 2] REAL

END - - of module WeaterhReporting

Change this ASN.1 module, so that the same coding is specified, but with tag defaults IMPLICIT instead of EXPLICIT.

Solution alternative 1 to Exercise 21

WeatherReporting {2 6 6 247 1} DEFINITIONS IMPLICIT TAGS ::=

BEGIN

WeatherReport ::= SEQUENCE {
      height [0] REAL,
      weather [1] Wrecord
}

Wrecord ::= [APPLICATION 3] EXPLICIT SEQUENCE {
      temp Temperature,
      moist Moisture
      wspeed [0] EXPLICIT Windspeed OPTIONAL
}

Temperature ::= [APPLICATION 0] REAL

Moisture ::= [APPLICATION 1] EXPLICIT REAL

Windspeed ::= [APPLICATION 2] EXPLICIT REAL

END - - of module WeaterhReporting

Exercise 22

Which tags below can be removed in correct ASN.1, not using automatic tagging?

Colour ::= [APPLICATION 0] CHOICE {
      rgb [1] RGB-Colour,
      cmg [2] CMG-Colour,
      freq [3] Frequency
}

RGB-Colour ::= [APPLICATION 1] SEQUENCE {
      red [0] REAL,
      green [1] REAL OPTIONAL,
      blue [2] REAL
}

CMG-Colour ::= SET {
      cyan [1] REAL,
      magenta [2] REAL,
      green [3] REAL
}

Frequency ::= SET {
      fullness [0] REAL,
      freq [1] REAL
}

Solution alternative 1 to Exercise 22

Tags which can be removed are shown as italics below.

Colour ::= [APPLICATION 0] CHOICE {
      rgb
[1] RGB-Colour,
      cmg
[2] CMG-Colour,
      freq [3] Frequency
}

RGB-Colour ::= [APPLICATION 1] SEQUENCE {
      red
[0] REAL,
      green
[1] REAL OPTIONAL,
      blue [2] REAL
}

CMG-Colour ::= SET {
      cyan
[1] REAL,
      magenta [2] REAL,
      green [3] REAL
}

Frequency ::= SET {
      fullness
[0] REAL,
      freq [1] REAL
}

Exercise 23

The following ASN.1 construct is taken from the 1988 version of the X.500 standard. OPTIONALLY-SIGNED is a macro, macros were replaced with a new construct in the 1994 version of ASN.1.

ListResult ::= OPTIONALLY-SIGNED
CHOICE {
      listInfo SET {
      DistinguishedName OPTIONAL,
      subordinates [1]            SET OF SEQUENCE {
            RelativeDistinguishedName,
            aliasEntry [0] BOOLEAN DEFAULT FALSE
            fromEntry [1] BOOLEAN DEFAULT TRUE},
      partialOutcomeQualifier [2]
                                          PartialOutcomeQualifier OPTIONAL
          COMPONENTS OF CommonResults },
uncorrelatedListInfo            [0] SET OF
                                                ListResult }

(a) Change the construct so that the indentations show the structure more clearly.

Solution alternative 1 to Exercise 23a

ListResult ::= OPTIONALLY-SIGNED
CHOICE {
      listInfo SET {
            DistinguishedName OPTIONAL,
            subordinates [1] SET OF SEQUENCE {
                  RelativeDistinguishedName,
                  aliasEntry [0] BOOLEAN DEFAULT FALSE
                  fromEntry [1] BOOLEAN DEFAULT TRUE},
            partialOutcomeQualifier [2]
                        PartialOutcomeQualifier OPTIONAL
      COMPONENTS OF CommonResults },
uncorrelatedListInfo [0] SET OF Listresult }

(b) Is there anything wrong in the ASN.1 code??

Solution alternative 1 to Exercise 23b

OPTIONALLY-SIGNED is a macro, and macros were allowed in 1988 ASN.1, but has been forbidden in later versions of the ASN.1 language.

Yes, two comma characters are missing, see below

ListResult ::= OPTIONALLY-SIGNED
CHOICE {
      listInfo SET {
            DistinguishedName OPTIONAL,
            subordinates [1] SET OF SEQUENCE {
                  RelativeDistinguishedName,
                  aliasEntry [0] BOOLEAN DEFAULT FALSE
,
                  fromEntry [1] BOOLEAN DEFAULT TRUE},
      partialOutcomeQualifier [2]
            PartialOutcomeQualifier OPTIONAL
,
      COMPONENTS OF CommonResults },
      uncorrelatedListInfo [0] SET OF Listresult }

(c) Why is there no identifier on the element COMPONENTS OF? What does it mean?

Solution alternative 1 to Exercise 23c

Answer: COMPONENTS OF is not a data type, and can thus not have any identifier. It copies a series of separately defined type elements, and is useful if you have a series of standard elements, like CommonResults, which is to be used in many places.

Solution alternative 1 to Exercise 23d

(d) Why is there no context-dependent tags on some of the elements, but not on all of them?

Answer: in a SET all the elements must have different type. It is then only necessary to give a context tag on all but one of the elements.

Exercise 24 (After sid 66)

Given the following ASN.1 module:

Driving {1 2 4711 17} DEFINITIONS EXPLICIT TAGS ::=
BEGIN

MainOperation ::= SEQUENCE {
      wheel [0] REAL,
      brake [1] REAL,
      gas [2] REAL
}

END

Define an ASN.1 module CarDriving, which imports MainOperation from the module above, and defines a new datatype FullOperation which in addition to MainOperation also includes switching on and of the left and right blinking lights, and setting the lights as unlit, parking lights, dimmed light and full beam.

Solution alternative 1 to Exercise 24

CarDriving { 1 2 4711 18 } DEFINITIONS EXPLICIT TAGS ::=
BEGIN
IMPORTS MainOperation FROM Driving {1 2 4711 17};

      FullOperation ::= SEQUENCE {
            COMPONENTS OF MainOperation,
            blink SEQUENCE {
            on BOOLEAN,
            left BOOLEAN
      },
      light ENUMERATED {
            dark(0),
            parkingLight (1),
            dimmedLight (2),
            fullBeam (3)
      }
}
END - - of module CarDriving

Note: Since there was no EXPORTS statement in Driving, all objects in it are exported.

Exercise 25 (After sid 75)

Given the ASN.1 definition

Surname ::= [APPLICATION 1] IA5String

hername Surname ::= "Mary"

Show its conding in BER.

Solution alternative 1 to Exercise 25

APPLICATION

CONSTRUCTED

Tag nr.

Length

UNIVERSAL

PRIMITIVE

IA5STRING

Length

01

1

00001

6

00

0

10110

4

M

a

r

y

61

06

16

04

M

a

r

y

Exercise 26

Given the ASN.1 definition

Light ::= ENUMERATED {
      dark (0),
      parkingLight (1),
      halfLight (2),
      fullLight (3) }

daylight Light ::= halflight

give a BER encoding of this value.

Solution alternative 1 to Exercise 26

Exercise 27

Given the following ASN.1 defintions and explicit tags

BreakFast ::= CHOICE {
      continental [0] Continental,
      english [1] English,
      american [2] American
}

Continental ::= SEQUENCE {
      beverage [1] ENUMERATED {
      coffea (0), tea(1), milk(2), chocolade (3) } OPTIONAL,
      jam [2] ENUMERATED {
      orange(0), strawberry(1), lingonberry(3) } OPTIONAL
}

English ::= SEQUENCE {
      continentalpart Continental,
      eggform ENUMERATED {
      soft(0), hard(1), scrambled(2), fried(3)
}

Order ::= SEQUENCE {
      customername IA5String,
      typeofbreakfast Breakfast
}

firstorder Order ::= {
      customername "Johan",
      typeofbreakfast {
            english {
            continentalpart {
                  beverage tea,
                  jam orange
                  }
            eggform fried
            }
      }
}

Give an encoding of firstorder with BER.

Solution alternative 1 to Exercise 27

(I make no promise that this is fully correct!)

element

encoding

Number of octets

beverage

(context explicit tag)101 00001
(ENUMERATED) 000 01010

-- 2

tea

(length) 1 (value) 00000001

-- 2

 

jam

(contextexplicit tag) 101 00010
(ENUMERATED) 000 01010

-- 2

 

orange

(length) 1 (value) 00000000

-- 2

 

continentalpart

(SEQUENCE) 001 10000 (length) 8
beverage tea jam orange

-- 10

 

eggform fried

(ENUMERATED) 000 01010 (length) 1
(value) 00000101

-- 3

english

(SEQUENCE) 001 10000 (length) 10
continentalpart

-- 12

 

typeofbreakfast

(context explicit tag) 100 00001
(length) 12 english

-- 14

 

customername

(IA5string) 00010110 (length) 5
("Johan") "J" "o" "h" "a" "n"

-- 7

 

firstorder

(SEQUENCE) 001 10000 (length) 21 customername typeofbreakfast

-- 23

Exercise 28 (on ABNF)

An identifier in a programming language is allowed to contain between 1 and 6 letters and digits, the first character must be a digit. Only upper case character are used. Write an ABNF specification for the syntax of such an identifier.

Solution alternative 1 to Exercise 8

ALPHA = "A" / "B" / "C" / "D" / "E" / "F" / "G" / "H" / "I" / "J" / "K" / "L" / "M" / "N" / "O" / "P" / "Q" / "R" / "S" / "T" / "U" / "V" / "X" / "Y" / "Z"

DIGIT = "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"

Identifier = ALPHA *5( ALPHA / DIGIT )

Exercise 29

Exercise 20 said that a society used two kinds of votes:

(a) The voters can select one and only one of 1 .. N alternatives. The alternative which gets the most total votes wins.

(b) The voters can indicate a score of between 0 and 10 for each of the choices 1 .. N. The choice which gets highest total score wins.

Suggest a textual encoding of this using ABNF.

Solution alternative 1 to Exercise 29

Vote = Voter-name "," (One-choice / Choice-list )
Voter-name = <"> Name <">
Name = 1*Namechar
Namechar = <any printable ASCII character except <"> and "\">
/ "\\" / "\""
One-choice = "Single:" 1*DIGIT
Choice-list = "Multiple:" 1#(Alternative Score)
Alternative = 1*DIGIT
Score = = "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9" / "10"

Compare this with the ASN.1-solution of Excersise 20:

Vote ::= SEQUENCE {
      voterName IA5String,
      CHOICE {
      chosenAlternative AlternativeNumber,
      SET OF SEQUENCE {
            alternative AlternativeNumber,
            score INTEGER ( 0 .. 10 )
            }
      }
}