I'm currently reading Javascript: The Good Parts and I'm having trouble understanding their "grammar" diagrams.
The first one is Whitespace
I'm not quite sure how to read it, perhaps some code will help me understand?
Thanks for the help in advanced guys.
The JavaScript Diagram is a feature-rich library for visualizing, creating, and editing interactive diagrams. It supports creating flowcharts, organizational charts, mind maps, and BPMN charts either through code or a visual interface.
The process of creating a JavaScript-based Sankey diagram can be split into four steps: Create an HTML page. Add scripts. Set data. Write some JS code. Let’s go through them together. 1. Create an HTML page To start with, create a basic HTML page to hold the intended Sankey chart and define a block element in it.
The diagram tool is written 100% in JavaScript and uses the HTML5 Canvas element for drawing. The component can use either jQuery or Microsoft Ajax® library for browser independence layer and type system implementation.
Our JavaScript Diagram Library has predefined alignment commands that enable you to align the selected objects’ nodes and connectors with respect to the selection boundary. Spacing commands enable you to place selected objects on the diagram at equal intervals from each other.
Start at the left-most ||
and continue right. The first bar down (Immediately next to your start point) cannot be followed because the curve does not originate from the left (The direction you are traveling.) If you look at where it comes from, it should be easy to tell it represents a while
loop:
while (!EOF) {} // While there's still text to parse
The second line can be followed because the curve originates from the left (Following your current directory.) This line represents this if-else statement:
if (char == '/') {} // Forward slash
else if (char == '\n') {} // Line end
else if (char == '\t') {} // Tab
else if (char == ' ') {} // Space
Space, tab and end line both both end the function and either return
or continue
immediately. However, if the character is a Forward Slash, it needs to check whether it's single line (//
) or multiline (/* */
):
*char++; // Move to next character
if (char == '*') {} // Multi line
else if (char == '/') {} // Single line
If it's a single line it reads until the end of the line and continues. If it is a multiline it reads in a similar manner until it finds '*' followed by '/' and then continues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With