“Javascript, The Good Parts”: Railroad Diagrams

后端 未结 3 1671
攒了一身酷
攒了一身酷 2020-12-31 03:54

I\'m reading \"Javascript, The Good Parts\" by Douglas Crockford, and having a difficulty understanding the use of all the railroad diagrams. He also doesn\'t elaborate much

相关标签:
3条回答
  • 2020-12-31 04:34

    This IBM page probably has the simplest explanation.

    The Wikipedia page offers more info in how to construct them.

    0 讨论(0)
  • 2020-12-31 04:38

    Railroad diagrams (Syntax diagrams, http://en.wikipedia.org/wiki/Syntax_diagram) are a graphical way to explain a grammar. If all you want to do is understand a railroad diagram, understand that you start at the left, and follow the line (track). And when you encounter a symbol/name, you go follow that track, until it is done, and then come back where you left off.

    Also, reading about BNF and EBNF (Extended? Backus-Naur Formalism, http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form) which is a formal way of describing a language grammar, using a set of productions, or rewrite rules. BNF/EBNF work the same as railroad diagrams, but using symbolic notation, the ::= production symbol, and a more formal/mathematical way to document a grammar.

    0 讨论(0)
  • 2020-12-31 04:47

    I am also reading this book. It takes me a long time, but finally understand Railroad Diagrams.

    First, as @ChuckCottrill mentioned, you should have a basic acknowledge about Syntax Diagrams and BNF/EBNF. But after reading that, it still confused me until I compare three graphs of different situation:

    zero or more, zero or one, one or more

    To understand their differences (as the following picture shows), the point is "You start on the left edge and follow the tracks to the right edge." So imagine you are the train, you just turn right, cannot turn left.

    the above picture created by http://bottlecaps.de/rr/ In the "Edit Grammar" tab, input the following grammar:

    zeroormore ::= element*
    zeroorone ::= element?
    oneormore ::= element+
    
    0 讨论(0)
提交回复
热议问题