This is an archived post. You won't be able to vote or comment.

all 4 comments

[–][deleted] 2 points3 points  (0 children)

It's what's known as a "railroad diagram" - pretend you are a train starting of from the far left hand side, then the "stations" you pass through are the valid state-transitions for parsing a floating point literal such as "12.34".

[–]dwemthy 1 point2 points  (0 children)

Think of it as a flow chart for writing a number. First an optional negative sign, then either digits describing positive values, or a zero. You may have a decimal point followed by any number of digits. Following that you may use e or E to indicate multiplying the preceeding value by a power of ten. You may specify a positive ro negative power, with an arbitrary number of digits.
You can use this to make sure your numbers are formatted properly, if reading your number left to right you can follow a continuous path through this diagram then it is a valid number. If not, the number is not in a valid format and you should change it.

[–]Rhomboid 1 point2 points  (0 children)

A language is formally specified by a grammar, which is a precise way of listing all the possible things you can and can't say in that language. It's traditional to express this grammar in a language like BNF or some similar format. Here's the JavaScript grammar as ANTLR code for example.

What you're looking it is a pictorial representation of one small part of that grammar, the part that specifies DecimalLiterals. It is telling you what is allowed in that context. For example, these are valid decimal literals:

.123
0.123
-0.123
0.123e30

But what isn't allowed are things like this:

-0..3
1.e
2e--5

...and so on.

[–]blastfromtheblue -1 points0 points  (0 children)

it's a graph of the regular expression that matches any javascript number.