Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I read this javascript diagram?

Tags:

javascript

I'm currently reading Javascript: The Good Parts and I'm having trouble understanding their "grammar" diagrams.

The first one is Whitespace

enter image description here

I'm not quite sure how to read it, perhaps some code will help me understand?

Thanks for the help in advanced guys.

like image 210
RufioLJ Avatar asked Oct 08 '12 04:10

RufioLJ


People also ask

What is the JavaScript diagram library?

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.

How to create a Sankey diagram in JavaScript?

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.

What programming language is the diagram tool written in?

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.

How to align objects on a JavaScript diagram library?

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.


1 Answers

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.

like image 190
rrowland Avatar answered Sep 28 '22 06:09

rrowland