简体   繁体   中英

JavaScript the Good Parts Diagrams

This question is asked before.

I have already been to these threads - Thread 1 , Thread 2

I have just started reading JavaScript the Good Parts and it consists of railroad diagrams which i can't understand even after visiting Wikipedia. You can't just skip them, there are lot's of them. I don't even know why they are so confusing, i found JavaScript to be easy.

Let's take these diagrams for example.

分数铁路图

指数铁路图

Correct me if i'm wrong, or just tell me if i am studying these diagrams the right way, below.


For the first diagram , you start from the left, you encounter the "decimal point", Now there are two options. If we just go straight ahead , does that mean only a decimal point without any digit ahead is considered a fraction or is it assumed that there will be a zero ahead by javascript?

On the Second Route , we encounter decimal point and then we add a digit to it and then we have a choice either to add more digits in a loop or go ahead and finish with the digit.


For the second diagram , I am lost.

The first diagram means that a fraction is a sequence starting with a dot and followed by zero or more (possibly infinite) digits.

The second diagram means that an exponent starts off with either "e" or "E" then has an optional sign ("-"/"+") and then one or more digits.

In general those vertical segments with forks show various options that can be taken, while the loop represents that they can be run through zero or multiple times.

I had to pull my copy of the book off the shelf, but now I get it. The railroad diagram for 'fraction' is part of the larger railroad diagram for 'number literal' which looks like: integer[fraction][exponent] . Taken in that context, it's correct... you can have just a dot after the integer part of a number as in var num = 1.;

In the second diagram, branches represent valid choices. So you start with e or E. Then have a +, -, or nothing (which is the same as +). And finally a sequence of zero or more digits.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM