Created
October 2, 2014 23:25
-
-
Save Zirak/1415882a6632d021c62a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NumericLiteral :: | |
DecimalLiteral | |
HexIntegerLiteral | |
OctalIntegerLiteral | |
DecimalLiteral :: | |
DecimalIntegerLiteral . DecimalDigits(opt) ExponentPart(opt) | |
... | |
DecimalIntegerLiteral :: | |
0 | |
NonZeroDigit DecimalDigits(opt) | |
... | |
OctalIntegerLiteral :: | |
0 OctalDigit | |
OctalIntegerLiteral OctalDigit | |
... | |
Let's start parsing! ^ indicates which character we're on | |
010 | |
^ | |
Hey, that's a number. Time to pass it to NumericLiteral. | |
NumericLiteral | |
DecimalLiteral | |
DecimalIntegerLiteral | |
0 [end] | |
010 | |
^ | |
Hang on...in DecimalIntegerLiteral, it says we can't have anything after a 0! | |
Fail. Guess we're not a DecimalIntegerLiteral, and nothing else matches in | |
DecimalLiteral. Let's try again. | |
010 | |
^ | |
NumericLiteral | |
HexIntegerLiteral | |
0 x HexDigit | |
Well, our 0 matches, but it's not followed by any x. Another fail. Let's try | |
again. | |
NumericLiteral | |
OctalIntegerLiteral | |
0 OctalDigit | |
Whadya know, our 0 matches. | |
(MV = 0) | |
010 | |
^ | |
(MV = 0*8 + 1 = 1) | |
And 1 is an OctalDigit, matches as well! | |
010 | |
^ | |
(MV = 1*8 + 0 = 8) | |
And so is that last 0! Huzzah! | |
MV = 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment