Question

In EMCA262 version 5.1 the definition of a hexadecimal integer literal is: (document page 20, PDF page 32)

HexIntegerLiteral ::
    0xHexDigit
    0XHexDigit
    HexIntegerLiteral HexDigit

HexDigit :: one of
    0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F

The way I understand it an HIL can look like this:

(HIL (HIL (HIL (HIL (HIL (HIL HD))))))

An HIL can look like 0x0 (that is 0x and a Hex Digit) and an HD can be 0, so an HIL can be 0x00x00x00x00x00

Obviously no implementation works like this, so I'm clearly misunderstanding something. How should I interpret (in my mind) this recursive definition?

Was it helpful?

Solution

The definition may be recursive but it doesn't work like that. Basically, it says that a HexIntegerLiteral is one of:

  • the case-insensitive prefix 0x followed by one hex digit, or
  • a HexIntegerLiteral followed by one hex digit

0x00x00 does not follow this definition. Here is why:

0x0

This is obviously a HIL by the first production.

0x00

This is also a HIL by the second production: the HIL 0x0 (established above) is followed by the hex digit 0.

0x00x

This is not a HIL, because:

  1. It is obviously not a result of the first production
  2. It is also not a result of the second production: the established HIL 0x00 from above is followed by something other than a hex digit.

In other words, the grammar above does not allow this:

(HIL (HIL (HIL (HIL (HIL (HIL HD))))))

What it allows is this:

(HIL (HD (HD (HD (HD (HD))))))

OTHER TIPS

HexIntegerLiteral is defined as 0X or 0X followed by one of 0-F, like...

//  vv----`0x`
    0x5
//    ^---Hex Digit

...OR as HexIntegerLiteral followed by one of 0-F, like...

//  vvv----HexIntegerLiteral
    0x54
//     ^---Hex Digit

...or...

//  vvvv----HexIntegerLiteral
    0x546
//      ^---Hex Digit

It may seem clearer if you work backwards.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top