summaryrefslogtreecommitdiff
path: root/docs/chapter03
diff options
context:
space:
mode:
authorDibyendu Majumdar <mobile@majumdar.org.uk>2023-10-01 18:01:54 +0100
committerDibyendu Majumdar <mobile@majumdar.org.uk>2025-06-13 15:42:08 -0700
commitff78e6164e127856fd41e3bc5eadb66ed819381a (patch)
tree83399842a87e66a3840b248d7b1686be814eb003 /docs/chapter03
parent0c1949a40dae7770045d64cb97036e6072b99dfd (diff)
downloadSimple-ff78e6164e127856fd41e3bc5eadb66ed819381a.tar.gz
Simple-ff78e6164e127856fd41e3bc5eadb66ed819381a.zip
Chapter 3: Variable Declarations
Co-authored-by: Cliff Click <cliffc@acm.org> Co-authored-by: Yichen Yan <oraluben@outlook.com> Co-authored-by: Thalia Archibald <thalia@archibald.dev> Co-authored-by: Tamas Hadhazy <helsgithub15@gmail.com> Co-authored-by: XmiliaH <45106915+XmiliaH@users.noreply.github.com> Co-authored-by: Tamás Hadházy <85063808+Hels15@users.noreply.github.com> Co-authored-by: tannal <tannal2409@gmail.com> Co-authored-by: hadha <helsgithub15@gmail.com> Co-authored-by: godalming123 <68993177+godalming123@users.noreply.github.com> Co-authored-by: RobertObkircher <robert.obkircher@gmail.com>
Diffstat (limited to 'docs/chapter03')
-rw-r--r--docs/chapter03/03-grammar.md72
-rw-r--r--docs/chapter03/03-graph1.gv39
-rw-r--r--docs/chapter03/03-graph1.svg136
-rw-r--r--docs/chapter03/03-graph2.gv35
-rw-r--r--docs/chapter03/03-graph2.svg137
-rw-r--r--docs/chapter03/03-graph3.gv37
-rw-r--r--docs/chapter03/03-graph3.svg151
-rw-r--r--docs/chapter03/03-graph4.svg127
-rw-r--r--docs/chapter03/03-graph5.svg127
-rw-r--r--docs/chapter03/Makefile12
-rw-r--r--docs/chapter03/README.md197
11 files changed, 1070 insertions, 0 deletions
diff --git a/docs/chapter03/03-grammar.md b/docs/chapter03/03-grammar.md
new file mode 100644
index 00000000..14a7d5fa
--- /dev/null
+++ b/docs/chapter03/03-grammar.md
@@ -0,0 +1,72 @@
+# Grammar for Chapter 1
+
+```antlrv4
+grammar SimpleLanguage;
+
+program
+ : statement+ EOF
+ ;
+
+statement
+ : returnStatement
+ | declStatement
+ | blockStatment
+ | expressionStatement
+ | metaStatement
+ ;
+
+metaStatement
+ : '#showGraph' ';'
+ ;
+
+expressionStatement
+ : IDENTIFIER '=' expression ';'
+ ;
+
+blockStatement
+ : '{' statement+ '}'
+ ;
+
+declStatement
+ : 'int' IDENTIFIER '=' expression ';'
+ ;
+
+returnStatement
+ : 'return' expression ';'
+ ;
+
+expression
+ : additiveExpression
+ ;
+
+additiveExpression
+ : multiplicativeExpression (('+' | '-') multiplicativeExpression)*
+ ;
+
+multiplicativeExpression
+ : unaryExpression (('*' | '/') unaryExpression)*
+ ;
+
+unaryExpression
+ : ('-') unaryExpression
+ | primaryExpression
+ ;
+
+primaryExpression
+ : IDENTIFIER
+ | INTEGER_LITERAL
+ | '(' expression ')'
+ ;
+
+INTEGER_LITERAL
+ : [1-9][0-9]*
+ | [0]
+ ;
+
+IDENTIFIER
+ : NON_DIGIT (NON_DIGIT | DIGIT)*
+ ;
+
+NON_DIGIT: [a-zA-Z_];
+DEC_DIGIT: [0-9];
+```
diff --git a/docs/chapter03/03-graph1.gv b/docs/chapter03/03-graph1.gv
new file mode 100644
index 00000000..2bdca351
--- /dev/null
+++ b/docs/chapter03/03-graph1.gv
@@ -0,0 +1,39 @@
+digraph chapter03 {
+/*
+int a=1; int b=2; int c=0; { int b=3; c=a+b; #showGraph; } return c; #showGraph;
+*/
+ rankdir=BT;
+ ordering="in";
+ concentrate="true";
+ subgraph cluster_Nodes {
+ Start2 [ shape=box style=filled fillcolor=yellow label="Start" ];
+ Con_3 [ label="#1" ];
+ Con_4 [ label="#2" ];
+ Con_6 [ label="#3" ];
+ Add7 [ label="+" ];
+ }
+ node [shape=plaintext];
+ subgraph cluster_Scope1_0 {
+ Scope1_0 [label=<
+ <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
+ <TR><TD BGCOLOR="cyan">0</TD><TD PORT="Scope1_0_a">a</TD><TD PORT="Scope1_0_b">b</TD><TD PORT="Scope1_0_c">c</TD></TR>
+ </TABLE>>];
+ subgraph cluster_Scope1_1 {
+ Scope1_1 [label=<
+ <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
+ <TR><TD BGCOLOR="cyan">1</TD><TD PORT="Scope1_1_b">b</TD></TR>
+ </TABLE>>];
+ }
+ }
+ edge [ fontname=Helvetica, fontsize=8 ];
+ Con_3 -> Start2[taillabel=0 style=dotted];
+ Con_4 -> Start2[taillabel=0 style=dotted];
+ Con_6 -> Start2[taillabel=0 style=dotted];
+ Add7 -> Con_3[taillabel=1];
+ Add7 -> Con_6[taillabel=2];
+ edge [style=dashed color=cornflowerblue];
+ Scope1_0:"Scope1_0_a" -> Con_3;
+ Scope1_0:"Scope1_0_b" -> Con_4;
+ Scope1_0:"Scope1_0_c" -> Add7;
+ Scope1_1:"Scope1_1_b" -> Con_6;
+}
diff --git a/docs/chapter03/03-graph1.svg b/docs/chapter03/03-graph1.svg
new file mode 100644
index 00000000..ab6f9600
--- /dev/null
+++ b/docs/chapter03/03-graph1.svg
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Generated by graphviz version 2.43.0 (0)
+ -->
+<!-- Title: chapter03 Pages: 1 -->
+<svg width="238pt" height="300pt"
+ viewBox="0.00 0.00 238.00 300.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 296)">
+<title>chapter03</title>
+<polygon fill="white" stroke="transparent" points="-4,4 -4,-296 234,-296 234,4 -4,4"/>
+<g id="clust1" class="cluster">
+<title>cluster_Nodes</title>
+<polygon fill="none" stroke="black" points="8,-88 8,-284 222,-284 222,-88 8,-88"/>
+</g>
+<g id="clust2" class="cluster">
+<title>cluster_Scope1_0</title>
+<polygon fill="none" stroke="black" points="36,-8 36,-76 210,-76 210,-8 36,-8"/>
+</g>
+<g id="clust3" class="cluster">
+<title>cluster_Scope1_1</title>
+<polygon fill="none" stroke="black" points="132,-16 132,-68 202,-68 202,-16 132,-16"/>
+</g>
+<!-- Start2 -->
+<g id="node1" class="node">
+<title>Start2</title>
+<polygon fill="yellow" stroke="black" points="142,-276 88,-276 88,-240 142,-240 142,-276"/>
+<text text-anchor="middle" x="115" y="-254.3" font-family="Times,serif" font-size="14.00">Start</text>
+</g>
+<!-- Con_3 -->
+<g id="node2" class="node">
+<title>Con_3</title>
+<ellipse fill="none" stroke="black" cx="43" cy="-186" rx="27" ry="18"/>
+<text text-anchor="middle" x="43" y="-182.3" font-family="Times,serif" font-size="14.00">#1</text>
+</g>
+<!-- Con_3&#45;&gt;Start2 -->
+<g id="edge1" class="edge">
+<title>Con_3&#45;&gt;Start2</title>
+<path fill="none" stroke="black" stroke-dasharray="1,5" d="M57.57,-201.17C66.92,-210.25 79.3,-222.29 90.17,-232.86"/>
+<polygon fill="black" stroke="black" points="87.79,-235.43 97.4,-239.89 92.67,-230.41 87.79,-235.43"/>
+<text text-anchor="middle" x="54.57" y="-203.77" font-family="Helvetica,sans-Serif" font-size="8.00">0</text>
+</g>
+<!-- Con_4 -->
+<g id="node3" class="node">
+<title>Con_4</title>
+<ellipse fill="none" stroke="black" cx="115" cy="-186" rx="27" ry="18"/>
+<text text-anchor="middle" x="115" y="-182.3" font-family="Times,serif" font-size="14.00">#2</text>
+</g>
+<!-- Con_4&#45;&gt;Start2 -->
+<g id="edge2" class="edge">
+<title>Con_4&#45;&gt;Start2</title>
+<path fill="none" stroke="black" stroke-dasharray="1,5" d="M115,-204.3C115,-212.02 115,-221.29 115,-229.89"/>
+<polygon fill="black" stroke="black" points="111.5,-229.9 115,-239.9 118.5,-229.9 111.5,-229.9"/>
+<text text-anchor="middle" x="112" y="-206.9" font-family="Helvetica,sans-Serif" font-size="8.00">0</text>
+</g>
+<!-- Con_6 -->
+<g id="node4" class="node">
+<title>Con_6</title>
+<ellipse fill="none" stroke="black" cx="187" cy="-186" rx="27" ry="18"/>
+<text text-anchor="middle" x="187" y="-182.3" font-family="Times,serif" font-size="14.00">#3</text>
+</g>
+<!-- Con_6&#45;&gt;Start2 -->
+<g id="edge3" class="edge">
+<title>Con_6&#45;&gt;Start2</title>
+<path fill="none" stroke="black" stroke-dasharray="1,5" d="M172.43,-201.17C163.08,-210.25 150.7,-222.29 139.83,-232.86"/>
+<polygon fill="black" stroke="black" points="137.33,-230.41 132.6,-239.89 142.21,-235.43 137.33,-230.41"/>
+<text text-anchor="middle" x="169.43" y="-203.77" font-family="Helvetica,sans-Serif" font-size="8.00">0</text>
+</g>
+<!-- Add7 -->
+<g id="node5" class="node">
+<title>Add7</title>
+<ellipse fill="none" stroke="black" cx="136" cy="-114" rx="27" ry="18"/>
+<text text-anchor="middle" x="136" y="-110.3" font-family="Times,serif" font-size="14.00">+</text>
+</g>
+<!-- Add7&#45;&gt;Con_3 -->
+<g id="edge4" class="edge">
+<title>Add7&#45;&gt;Con_3</title>
+<path fill="none" stroke="black" d="M118.51,-128.17C104.48,-138.73 84.58,-153.7 68.74,-165.63"/>
+<polygon fill="black" stroke="black" points="66.3,-163.08 60.41,-171.89 70.51,-168.68 66.3,-163.08"/>
+<text text-anchor="middle" x="115.51" y="-130.77" font-family="Helvetica,sans-Serif" font-size="8.00">1</text>
+</g>
+<!-- Add7&#45;&gt;Con_6 -->
+<g id="edge5" class="edge">
+<title>Add7&#45;&gt;Con_6</title>
+<path fill="none" stroke="black" d="M147.32,-130.54C153.92,-139.6 162.38,-151.21 169.8,-161.39"/>
+<polygon fill="black" stroke="black" points="167,-163.49 175.71,-169.51 172.65,-159.36 167,-163.49"/>
+<text text-anchor="middle" x="144.32" y="-133.14" font-family="Helvetica,sans-Serif" font-size="8.00">2</text>
+</g>
+<!-- Scope1_0 -->
+<g id="node6" class="node">
+<title>Scope1_0</title>
+<polygon fill="cyan" stroke="transparent" points="53,-31 53,-52 69,-52 69,-31 53,-31"/>
+<polygon fill="none" stroke="black" points="53,-31 53,-52 69,-52 69,-31 53,-31"/>
+<text text-anchor="start" x="56" y="-37.8" font-family="Times,serif" font-size="14.00">0</text>
+<polygon fill="none" stroke="black" points="69,-31 69,-52 84,-52 84,-31 69,-31"/>
+<text text-anchor="start" x="72" y="-37.8" font-family="Times,serif" font-size="14.00">a</text>
+<polygon fill="none" stroke="black" points="84,-31 84,-52 100,-52 100,-31 84,-31"/>
+<text text-anchor="start" x="87" y="-37.8" font-family="Times,serif" font-size="14.00">b</text>
+<polygon fill="none" stroke="black" points="100,-31 100,-52 114,-52 114,-31 100,-31"/>
+<text text-anchor="start" x="103" y="-37.8" font-family="Times,serif" font-size="14.00">c</text>
+</g>
+<!-- Scope1_0&#45;&gt;Con_3 -->
+<g id="edge6" class="edge">
+<title>Scope1_0:Scope1_0_a&#45;&gt;Con_3</title>
+<path fill="none" stroke="cornflowerblue" stroke-dasharray="5,2" d="M76,-53C76,-90.54 63.29,-132.33 53.64,-158.64"/>
+<polygon fill="cornflowerblue" stroke="cornflowerblue" points="50.27,-157.66 50,-168.25 56.81,-160.14 50.27,-157.66"/>
+</g>
+<!-- Scope1_0&#45;&gt;Con_4 -->
+<g id="edge7" class="edge">
+<title>Scope1_0:Scope1_0_b&#45;&gt;Con_4</title>
+<path fill="none" stroke="cornflowerblue" stroke-dasharray="5,2" d="M92,-53C92,-88.29 93.39,-97.33 100,-132 101.65,-140.68 104.07,-150 106.48,-158.37"/>
+<polygon fill="cornflowerblue" stroke="cornflowerblue" points="103.14,-159.42 109.37,-168 109.85,-157.41 103.14,-159.42"/>
+</g>
+<!-- Scope1_0&#45;&gt;Add7 -->
+<g id="edge8" class="edge">
+<title>Scope1_0:Scope1_0_c&#45;&gt;Add7</title>
+<path fill="none" stroke="cornflowerblue" stroke-dasharray="5,2" d="M107,-53C107,-65.71 112.34,-78.55 118.43,-89.08"/>
+<polygon fill="cornflowerblue" stroke="cornflowerblue" points="115.57,-91.1 123.87,-97.68 121.48,-87.35 115.57,-91.1"/>
+</g>
+<!-- Scope1_1 -->
+<g id="node7" class="node">
+<title>Scope1_1</title>
+<polygon fill="cyan" stroke="transparent" points="151,-31 151,-52 167,-52 167,-31 151,-31"/>
+<polygon fill="none" stroke="black" points="151,-31 151,-52 167,-52 167,-31 151,-31"/>
+<text text-anchor="start" x="154" y="-37.8" font-family="Times,serif" font-size="14.00">1</text>
+<polygon fill="none" stroke="black" points="167,-31 167,-52 183,-52 183,-31 167,-31"/>
+<text text-anchor="start" x="170" y="-37.8" font-family="Times,serif" font-size="14.00">b</text>
+</g>
+<!-- Scope1_1&#45;&gt;Con_6 -->
+<g id="edge9" class="edge">
+<title>Scope1_1:Scope1_1_b&#45;&gt;Con_6</title>
+<path fill="none" stroke="cornflowerblue" stroke-dasharray="5,2" d="M175,-53C175,-89.4 179.58,-131.23 183.08,-157.87"/>
+<polygon fill="cornflowerblue" stroke="cornflowerblue" points="179.64,-158.52 184.46,-167.96 186.58,-157.58 179.64,-158.52"/>
+</g>
+</g>
+</svg>
diff --git a/docs/chapter03/03-graph2.gv b/docs/chapter03/03-graph2.gv
new file mode 100644
index 00000000..460b63c8
--- /dev/null
+++ b/docs/chapter03/03-graph2.gv
@@ -0,0 +1,35 @@
+digraph chapter03 {
+/*
+int a=1; int b=2; int c=0; { int b=3; c=a+b; #showGraph; } return c; #showGraph;
+*/
+ rankdir=BT;
+ ordering="in";
+ concentrate="true";
+ subgraph cluster_Nodes {
+ Start2 [ shape=box style=filled fillcolor=yellow label="Start" ];
+ Con_3 [ label="#1" ];
+ Con_4 [ label="#2" ];
+ Con_6 [ label="#3" ];
+ Add7 [ label="+" ];
+ Return8 [ shape=box style=filled fillcolor=yellow label="Return" ];
+ }
+ node [shape=plaintext];
+ subgraph cluster_Scope1_0 {
+ Scope1_0 [label=<
+ <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
+ <TR><TD BGCOLOR="cyan">0</TD><TD PORT="Scope1_0_a">a</TD><TD PORT="Scope1_0_b">b</TD><TD PORT="Scope1_0_c">c</TD></TR>
+ </TABLE>>];
+ }
+ edge [ fontname=Helvetica, fontsize=8 ];
+ Con_3 -> Start2[taillabel=0 style=dotted];
+ Con_4 -> Start2[taillabel=0 style=dotted];
+ Con_6 -> Start2[taillabel=0 style=dotted];
+ Add7 -> Con_3[taillabel=1];
+ Add7 -> Con_6[taillabel=2];
+ Return8 -> Start2[taillabel=0 color=red];
+ Return8 -> Add7[taillabel=1];
+ edge [style=dashed color=cornflowerblue];
+ Scope1_0:"Scope1_0_a" -> Con_3;
+ Scope1_0:"Scope1_0_b" -> Con_4;
+ Scope1_0:"Scope1_0_c" -> Add7;
+}
diff --git a/docs/chapter03/03-graph2.svg b/docs/chapter03/03-graph2.svg
new file mode 100644
index 00000000..0a539c6a
--- /dev/null
+++ b/docs/chapter03/03-graph2.svg
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Generated by graphviz version 2.43.0 (0)
+ -->
+<!-- Title: chapter03 Pages: 1 -->
+<svg width="360pt" height="292pt"
+ viewBox="0.00 0.00 360.00 292.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 288)">
+<title>chapter03</title>
+<polygon fill="white" stroke="transparent" points="-4,4 -4,-288 356,-288 356,4 -4,4"/>
+<g id="clust1" class="cluster">
+<title>cluster_Nodes</title>
+<polygon fill="none" stroke="black" points="8,-8 8,-276 242,-276 242,-8 8,-8"/>
+</g>
+<g id="clust2" class="cluster">
+<title>cluster_Scope1_0</title>
+<polygon fill="none" stroke="black" points="250,-8 250,-60 344,-60 344,-8 250,-8"/>
+</g>
+<!-- Start2 -->
+<g id="node1" class="node">
+<title>Start2</title>
+<polygon fill="yellow" stroke="black" points="126,-268 72,-268 72,-232 126,-232 126,-268"/>
+<text text-anchor="middle" x="99" y="-246.3" font-family="Times,serif" font-size="14.00">Start</text>
+</g>
+<!-- Con_3 -->
+<g id="node2" class="node">
+<title>Con_3</title>
+<ellipse fill="none" stroke="black" cx="135" cy="-178" rx="27" ry="18"/>
+<text text-anchor="middle" x="135" y="-174.3" font-family="Times,serif" font-size="14.00">#1</text>
+</g>
+<!-- Con_3&#45;&gt;Start2 -->
+<g id="edge1" class="edge">
+<title>Con_3&#45;&gt;Start2</title>
+<path fill="none" stroke="black" stroke-dasharray="1,5" d="M126.65,-195.24C122.46,-203.39 117.27,-213.47 112.53,-222.69"/>
+<polygon fill="black" stroke="black" points="109.27,-221.38 107.81,-231.88 115.49,-224.58 109.27,-221.38"/>
+<text text-anchor="middle" x="123.65" y="-197.84" font-family="Helvetica,sans-Serif" font-size="8.00">0</text>
+</g>
+<!-- Con_4 -->
+<g id="node3" class="node">
+<title>Con_4</title>
+<ellipse fill="none" stroke="black" cx="207" cy="-178" rx="27" ry="18"/>
+<text text-anchor="middle" x="207" y="-174.3" font-family="Times,serif" font-size="14.00">#2</text>
+</g>
+<!-- Con_4&#45;&gt;Start2 -->
+<g id="edge2" class="edge">
+<title>Con_4&#45;&gt;Start2</title>
+<path fill="none" stroke="black" stroke-dasharray="1,5" d="M188.19,-191.19C173.23,-200.89 151.89,-214.72 133.84,-226.42"/>
+<polygon fill="black" stroke="black" points="131.77,-223.59 125.28,-231.97 135.58,-229.46 131.77,-223.59"/>
+<text text-anchor="middle" x="185.19" y="-193.79" font-family="Helvetica,sans-Serif" font-size="8.00">0</text>
+</g>
+<!-- Con_6 -->
+<g id="node4" class="node">
+<title>Con_6</title>
+<ellipse fill="none" stroke="black" cx="63" cy="-178" rx="27" ry="18"/>
+<text text-anchor="middle" x="63" y="-174.3" font-family="Times,serif" font-size="14.00">#3</text>
+</g>
+<!-- Con_6&#45;&gt;Start2 -->
+<g id="edge3" class="edge">
+<title>Con_6&#45;&gt;Start2</title>
+<path fill="none" stroke="black" stroke-dasharray="1,5" d="M71.35,-195.24C75.54,-203.39 80.73,-213.47 85.47,-222.69"/>
+<polygon fill="black" stroke="black" points="82.51,-224.58 90.19,-231.88 88.73,-221.38 82.51,-224.58"/>
+<text text-anchor="middle" x="68.35" y="-197.84" font-family="Helvetica,sans-Serif" font-size="8.00">0</text>
+</g>
+<!-- Add7 -->
+<g id="node5" class="node">
+<title>Add7</title>
+<ellipse fill="none" stroke="black" cx="71" cy="-106" rx="27" ry="18"/>
+<text text-anchor="middle" x="71" y="-102.3" font-family="Times,serif" font-size="14.00">+</text>
+</g>
+<!-- Add7&#45;&gt;Con_3 -->
+<g id="edge4" class="edge">
+<title>Add7&#45;&gt;Con_3</title>
+<path fill="none" stroke="black" d="M84.57,-121.85C93.31,-131.4 104.83,-144.01 114.66,-154.75"/>
+<polygon fill="black" stroke="black" points="112.12,-157.16 121.45,-162.18 117.28,-152.43 112.12,-157.16"/>
+<text text-anchor="middle" x="81.57" y="-124.45" font-family="Helvetica,sans-Serif" font-size="8.00">1</text>
+</g>
+<!-- Add7&#45;&gt;Con_6 -->
+<g id="edge5" class="edge">
+<title>Add7&#45;&gt;Con_6</title>
+<path fill="none" stroke="black" d="M69.02,-124.3C68.14,-132.02 67.08,-141.29 66.1,-149.89"/>
+<polygon fill="black" stroke="black" points="62.61,-149.56 64.95,-159.9 69.57,-150.36 62.61,-149.56"/>
+<text text-anchor="middle" x="66.02" y="-126.9" font-family="Helvetica,sans-Serif" font-size="8.00">2</text>
+</g>
+<!-- Return8 -->
+<g id="node6" class="node">
+<title>Return8</title>
+<polygon fill="yellow" stroke="black" points="89,-52 23,-52 23,-16 89,-16 89,-52"/>
+<text text-anchor="middle" x="56" y="-30.3" font-family="Times,serif" font-size="14.00">Return</text>
+</g>
+<!-- Return8&#45;&gt;Start2 -->
+<g id="edge6" class="edge">
+<title>Return8&#45;&gt;Start2</title>
+<path fill="none" stroke="red" d="M46.1,-52.47C30.13,-83.17 2.78,-148.1 27,-196 34.7,-211.23 49.06,-223.15 62.94,-231.8"/>
+<polygon fill="red" stroke="red" points="61.52,-235.02 71.92,-237.01 65.03,-228.96 61.52,-235.02"/>
+<text text-anchor="middle" x="43.1" y="-55.07" font-family="Helvetica,sans-Serif" font-size="8.00">0</text>
+</g>
+<!-- Return8&#45;&gt;Add7 -->
+<g id="edge7" class="edge">
+<title>Return8&#45;&gt;Add7</title>
+<path fill="none" stroke="black" d="M59.71,-52.3C61.36,-60.02 63.35,-69.29 65.19,-77.89"/>
+<polygon fill="black" stroke="black" points="61.82,-78.85 67.33,-87.9 68.66,-77.38 61.82,-78.85"/>
+<text text-anchor="middle" x="56.71" y="-54.9" font-family="Helvetica,sans-Serif" font-size="8.00">1</text>
+</g>
+<!-- Scope1_0 -->
+<g id="node7" class="node">
+<title>Scope1_0</title>
+<polygon fill="cyan" stroke="transparent" points="267,-23 267,-44 283,-44 283,-23 267,-23"/>
+<polygon fill="none" stroke="black" points="267,-23 267,-44 283,-44 283,-23 267,-23"/>
+<text text-anchor="start" x="270" y="-29.8" font-family="Times,serif" font-size="14.00">0</text>
+<polygon fill="none" stroke="black" points="283,-23 283,-44 298,-44 298,-23 283,-23"/>
+<text text-anchor="start" x="286" y="-29.8" font-family="Times,serif" font-size="14.00">a</text>
+<polygon fill="none" stroke="black" points="298,-23 298,-44 314,-44 314,-23 298,-23"/>
+<text text-anchor="start" x="301" y="-29.8" font-family="Times,serif" font-size="14.00">b</text>
+<polygon fill="none" stroke="black" points="314,-23 314,-44 328,-44 328,-23 314,-23"/>
+<text text-anchor="start" x="317" y="-29.8" font-family="Times,serif" font-size="14.00">c</text>
+</g>
+<!-- Scope1_0&#45;&gt;Con_3 -->
+<g id="edge8" class="edge">
+<title>Scope1_0:Scope1_0_a&#45;&gt;Con_3</title>
+<path fill="none" stroke="cornflowerblue" stroke-dasharray="5,2" d="M290,-45C290,-77.9 208.02,-132.76 163.3,-160.24"/>
+<polygon fill="cornflowerblue" stroke="cornflowerblue" points="161.36,-157.33 154.63,-165.51 164.99,-163.31 161.36,-157.33"/>
+</g>
+<!-- Scope1_0&#45;&gt;Con_4 -->
+<g id="edge9" class="edge">
+<title>Scope1_0:Scope1_0_b&#45;&gt;Con_4</title>
+<path fill="none" stroke="cornflowerblue" stroke-dasharray="5,2" d="M306,-45C306,-93.23 263.17,-135.12 233.85,-158.15"/>
+<polygon fill="cornflowerblue" stroke="cornflowerblue" points="231.47,-155.56 225.62,-164.4 235.7,-161.14 231.47,-155.56"/>
+</g>
+<!-- Scope1_0&#45;&gt;Add7 -->
+<g id="edge10" class="edge">
+<title>Scope1_0:Scope1_0_c&#45;&gt;Add7</title>
+<path fill="none" stroke="cornflowerblue" stroke-dasharray="5,2" d="M321,-45C321,-86.77 178.58,-78.08 138,-88 127.51,-90.56 116.11,-93.43 105.75,-96.06"/>
+<polygon fill="cornflowerblue" stroke="cornflowerblue" points="104.62,-92.74 95.79,-98.6 106.35,-99.52 104.62,-92.74"/>
+</g>
+</g>
+</svg>
diff --git a/docs/chapter03/03-graph3.gv b/docs/chapter03/03-graph3.gv
new file mode 100644
index 00000000..50cb6d27
--- /dev/null
+++ b/docs/chapter03/03-graph3.gv
@@ -0,0 +1,37 @@
+digraph chapter03 {
+/*
+int x0=1; int y0=2; int x1=3; int y1=4; return (x0-x1)*(x0-x1) + (y0-y1)*(y0-y1); #showGraph;
+*/
+ rankdir=BT;
+ ordering="in";
+ concentrate="true";
+ subgraph cluster_Nodes {
+ Start2 [ shape=box style=filled fillcolor=yellow label="Start" ];
+ Con_3 [ label="#1" ];
+ Con_4 [ label="#2" ];
+ Con_20 [ label="#8" ];
+ Con_5 [ label="#3" ];
+ Return21 [ shape=box style=filled fillcolor=yellow label="Return" ];
+ Con_6 [ label="#4" ];
+ }
+ node [shape=plaintext];
+ subgraph cluster_Scope1_0 {
+ Scope1_0 [label=<
+ <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
+ <TR><TD BGCOLOR="cyan">0</TD><TD PORT="Scope1_0_y0">y0</TD><TD PORT="Scope1_0_x0">x0</TD><TD PORT="Scope1_0_y1">y1</TD><TD PORT="Scope1_0_x1">x1</TD></TR>
+ </TABLE>>];
+ }
+ edge [ fontname=Helvetica, fontsize=8 ];
+ Con_3 -> Start2[taillabel=0 style=dotted];
+ Con_4 -> Start2[taillabel=0 style=dotted];
+ Con_20 -> Start2[taillabel=0 style=dotted];
+ Con_5 -> Start2[taillabel=0 style=dotted];
+ Return21 -> Start2[taillabel=0 color=red];
+ Return21 -> Con_20[taillabel=1];
+ Con_6 -> Start2[taillabel=0 style=dotted];
+ edge [style=dashed color=cornflowerblue];
+ Scope1_0:"Scope1_0_y0" -> Con_4;
+ Scope1_0:"Scope1_0_x0" -> Con_3;
+ Scope1_0:"Scope1_0_y1" -> Con_6;
+ Scope1_0:"Scope1_0_x1" -> Con_5;
+}
diff --git a/docs/chapter03/03-graph3.svg b/docs/chapter03/03-graph3.svg
new file mode 100644
index 00000000..623bd902
--- /dev/null
+++ b/docs/chapter03/03-graph3.svg
@@ -0,0 +1,151 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Generated by graphviz version 2.43.0 (0)
+ -->
+<!-- Title: chapter03 Pages: 1 -->
+<svg width="554pt" height="220pt"
+ viewBox="0.00 0.00 554.00 220.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 216)">
+<title>chapter03</title>
+<polygon fill="white" stroke="transparent" points="-4,4 -4,-216 550,-216 550,4 -4,4"/>
+<g id="clust1" class="cluster">
+<title>cluster_Nodes</title>
+<polygon fill="none" stroke="black" points="8,-8 8,-204 386,-204 386,-8 8,-8"/>
+</g>
+<g id="clust2" class="cluster">
+<title>cluster_Scope1_0</title>
+<polygon fill="none" stroke="black" points="394,-8 394,-60 538,-60 538,-8 394,-8"/>
+</g>
+<!-- Start2 -->
+<g id="node1" class="node">
+<title>Start2</title>
+<polygon fill="yellow" stroke="black" points="198,-196 144,-196 144,-160 198,-160 198,-196"/>
+<text text-anchor="middle" x="171" y="-174.3" font-family="Times,serif" font-size="14.00">Start</text>
+</g>
+<!-- Con_3 -->
+<g id="node2" class="node">
+<title>Con_3</title>
+<ellipse fill="none" stroke="black" cx="207" cy="-106" rx="27" ry="18"/>
+<text text-anchor="middle" x="207" y="-102.3" font-family="Times,serif" font-size="14.00">#1</text>
+</g>
+<!-- Con_3&#45;&gt;Start2 -->
+<g id="edge1" class="edge">
+<title>Con_3&#45;&gt;Start2</title>
+<path fill="none" stroke="black" stroke-dasharray="1,5" d="M198.65,-123.24C194.46,-131.39 189.27,-141.47 184.53,-150.69"/>
+<polygon fill="black" stroke="black" points="181.27,-149.38 179.81,-159.88 187.49,-152.58 181.27,-149.38"/>
+<text text-anchor="middle" x="195.65" y="-125.84" font-family="Helvetica,sans-Serif" font-size="8.00">0</text>
+</g>
+<!-- Con_4 -->
+<g id="node3" class="node">
+<title>Con_4</title>
+<ellipse fill="none" stroke="black" cx="135" cy="-106" rx="27" ry="18"/>
+<text text-anchor="middle" x="135" y="-102.3" font-family="Times,serif" font-size="14.00">#2</text>
+</g>
+<!-- Con_4&#45;&gt;Start2 -->
+<g id="edge2" class="edge">
+<title>Con_4&#45;&gt;Start2</title>
+<path fill="none" stroke="black" stroke-dasharray="1,5" d="M143.35,-123.24C147.54,-131.39 152.73,-141.47 157.47,-150.69"/>
+<polygon fill="black" stroke="black" points="154.51,-152.58 162.19,-159.88 160.73,-149.38 154.51,-152.58"/>
+<text text-anchor="middle" x="140.35" y="-125.84" font-family="Helvetica,sans-Serif" font-size="8.00">0</text>
+</g>
+<!-- Con_20 -->
+<g id="node4" class="node">
+<title>Con_20</title>
+<ellipse fill="none" stroke="black" cx="63" cy="-106" rx="27" ry="18"/>
+<text text-anchor="middle" x="63" y="-102.3" font-family="Times,serif" font-size="14.00">#8</text>
+</g>
+<!-- Con_20&#45;&gt;Start2 -->
+<g id="edge3" class="edge">
+<title>Con_20&#45;&gt;Start2</title>
+<path fill="none" stroke="black" stroke-dasharray="1,5" d="M81.81,-119.19C96.77,-128.89 118.11,-142.72 136.16,-154.42"/>
+<polygon fill="black" stroke="black" points="134.42,-157.46 144.72,-159.97 138.23,-151.59 134.42,-157.46"/>
+<text text-anchor="middle" x="78.81" y="-121.79" font-family="Helvetica,sans-Serif" font-size="8.00">0</text>
+</g>
+<!-- Con_5 -->
+<g id="node5" class="node">
+<title>Con_5</title>
+<ellipse fill="none" stroke="black" cx="351" cy="-106" rx="27" ry="18"/>
+<text text-anchor="middle" x="351" y="-102.3" font-family="Times,serif" font-size="14.00">#3</text>
+</g>
+<!-- Con_5&#45;&gt;Start2 -->
+<g id="edge4" class="edge">
+<title>Con_5&#45;&gt;Start2</title>
+<path fill="none" stroke="black" stroke-dasharray="1,5" d="M329.82,-117.38C324.99,-119.65 319.84,-121.97 315,-124 279.07,-139.06 237.19,-154.21 207.89,-164.43"/>
+<polygon fill="black" stroke="black" points="206.38,-161.25 198.08,-167.84 208.68,-167.87 206.38,-161.25"/>
+<text text-anchor="middle" x="326.82" y="-119.98" font-family="Helvetica,sans-Serif" font-size="8.00">0</text>
+</g>
+<!-- Return21 -->
+<g id="node6" class="node">
+<title>Return21</title>
+<polygon fill="yellow" stroke="black" points="89,-52 23,-52 23,-16 89,-16 89,-52"/>
+<text text-anchor="middle" x="56" y="-30.3" font-family="Times,serif" font-size="14.00">Return</text>
+</g>
+<!-- Return21&#45;&gt;Start2 -->
+<g id="edge5" class="edge">
+<title>Return21&#45;&gt;Start2</title>
+<path fill="none" stroke="red" d="M42.04,-52.06C28.34,-71.02 11.57,-101.87 27,-124 50.89,-158.26 99.53,-170.43 133.64,-174.72"/>
+<polygon fill="red" stroke="red" points="133.4,-178.22 143.72,-175.82 134.16,-171.26 133.4,-178.22"/>
+<text text-anchor="middle" x="39.04" y="-54.66" font-family="Helvetica,sans-Serif" font-size="8.00">0</text>
+</g>
+<!-- Return21&#45;&gt;Con_20 -->
+<g id="edge6" class="edge">
+<title>Return21&#45;&gt;Con_20</title>
+<path fill="none" stroke="black" d="M57.73,-52.3C58.5,-60.02 59.43,-69.29 60.29,-77.89"/>
+<polygon fill="black" stroke="black" points="56.81,-78.29 61.29,-87.9 63.78,-77.6 56.81,-78.29"/>
+<text text-anchor="middle" x="54.73" y="-54.9" font-family="Helvetica,sans-Serif" font-size="8.00">1</text>
+</g>
+<!-- Con_6 -->
+<g id="node7" class="node">
+<title>Con_6</title>
+<ellipse fill="none" stroke="black" cx="279" cy="-106" rx="27" ry="18"/>
+<text text-anchor="middle" x="279" y="-102.3" font-family="Times,serif" font-size="14.00">#4</text>
+</g>
+<!-- Con_6&#45;&gt;Start2 -->
+<g id="edge7" class="edge">
+<title>Con_6&#45;&gt;Start2</title>
+<path fill="none" stroke="black" stroke-dasharray="1,5" d="M260.19,-119.19C245.23,-128.89 223.89,-142.72 205.84,-154.42"/>
+<polygon fill="black" stroke="black" points="203.77,-151.59 197.28,-159.97 207.58,-157.46 203.77,-151.59"/>
+<text text-anchor="middle" x="257.19" y="-121.79" font-family="Helvetica,sans-Serif" font-size="8.00">0</text>
+</g>
+<!-- Scope1_0 -->
+<g id="node8" class="node">
+<title>Scope1_0</title>
+<polygon fill="cyan" stroke="transparent" points="410,-23 410,-44 426,-44 426,-23 410,-23"/>
+<polygon fill="none" stroke="black" points="410,-23 410,-44 426,-44 426,-23 410,-23"/>
+<text text-anchor="start" x="413" y="-29.8" font-family="Times,serif" font-size="14.00">0</text>
+<polygon fill="none" stroke="black" points="426,-23 426,-44 450,-44 450,-23 426,-23"/>
+<text text-anchor="start" x="429" y="-29.8" font-family="Times,serif" font-size="14.00">y0</text>
+<polygon fill="none" stroke="black" points="450,-23 450,-44 474,-44 474,-23 450,-23"/>
+<text text-anchor="start" x="453" y="-29.8" font-family="Times,serif" font-size="14.00">x0</text>
+<polygon fill="none" stroke="black" points="474,-23 474,-44 498,-44 498,-23 474,-23"/>
+<text text-anchor="start" x="477" y="-29.8" font-family="Times,serif" font-size="14.00">y1</text>
+<polygon fill="none" stroke="black" points="498,-23 498,-44 522,-44 522,-23 498,-23"/>
+<text text-anchor="start" x="501" y="-29.8" font-family="Times,serif" font-size="14.00">x1</text>
+</g>
+<!-- Scope1_0&#45;&gt;Con_3 -->
+<g id="edge9" class="edge">
+<title>Scope1_0:Scope1_0_x0&#45;&gt;Con_3</title>
+<path fill="none" stroke="cornflowerblue" stroke-dasharray="5,2" d="M462,-45C462,-94.6 290.16,-72.65 243,-88 241.08,-88.63 239.12,-89.33 237.17,-90.09"/>
+<polygon fill="cornflowerblue" stroke="cornflowerblue" points="235.39,-87.04 227.58,-94.19 238.15,-93.48 235.39,-87.04"/>
+</g>
+<!-- Scope1_0&#45;&gt;Con_4 -->
+<g id="edge8" class="edge">
+<title>Scope1_0:Scope1_0_y0&#45;&gt;Con_4</title>
+<path fill="none" stroke="cornflowerblue" stroke-dasharray="5,2" d="M438,-45C438,-67.35 411.84,-55.23 390,-60 294.13,-80.94 265.19,-60.49 171,-88 169.06,-88.57 167.09,-89.23 165.13,-89.95"/>
+<polygon fill="cornflowerblue" stroke="cornflowerblue" points="163.39,-86.88 155.5,-93.97 166.08,-93.34 163.39,-86.88"/>
+</g>
+<!-- Scope1_0&#45;&gt;Con_5 -->
+<g id="edge11" class="edge">
+<title>Scope1_0:Scope1_0_x1&#45;&gt;Con_5</title>
+<path fill="none" stroke="cornflowerblue" stroke-dasharray="5,2" d="M510,-45C510,-71.13 433.9,-89.82 387,-98.86"/>
+<polygon fill="cornflowerblue" stroke="cornflowerblue" points="386.09,-95.47 376.9,-100.75 387.37,-102.35 386.09,-95.47"/>
+</g>
+<!-- Scope1_0&#45;&gt;Con_6 -->
+<g id="edge10" class="edge">
+<title>Scope1_0:Scope1_0_y1&#45;&gt;Con_6</title>
+<path fill="none" stroke="cornflowerblue" stroke-dasharray="5,2" d="M486,-45C486,-123.37 388.78,-61.59 315,-88 313.15,-88.66 311.26,-89.39 309.37,-90.16"/>
+<polygon fill="cornflowerblue" stroke="cornflowerblue" points="307.8,-87.02 300.03,-94.23 310.6,-93.44 307.8,-87.02"/>
+</g>
+</g>
+</svg>
diff --git a/docs/chapter03/03-graph4.svg b/docs/chapter03/03-graph4.svg
new file mode 100644
index 00000000..6838e1d4
--- /dev/null
+++ b/docs/chapter03/03-graph4.svg
@@ -0,0 +1,127 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Generated by graphviz version 2.40.1 (20161225.0304)
+ -->
+<!-- Title: chapter03 Pages: 1 -->
+<svg width="310pt" height="228pt" viewBox="0.00 0.00 310.00 228.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 224)">
+<title>chapter03</title>
+<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-224 306,-224 306,4 -4,4"/>
+<g id="clust1" class="cluster">
+<title>cluster_Nodes</title>
+<polygon fill="none" stroke="#000000" points="8,-88 8,-212 294,-212 294,-88 8,-88"/>
+</g>
+<g id="clust2" class="cluster">
+<title>cluster_Scope1_0</title>
+<polygon fill="none" stroke="#000000" points="97,-8 97,-76 259,-76 259,-8 97,-8"/>
+</g>
+<g id="clust3" class="cluster">
+<title>cluster_Scope1_1</title>
+<polygon fill="none" stroke="#000000" points="181,-16 181,-68 251,-68 251,-16 181,-16"/>
+</g>
+<!-- Start2 -->
+<g id="node1" class="node">
+<title>Start2</title>
+<polygon fill="#ffff00" stroke="#000000" points="178,-204 124,-204 124,-168 178,-168 178,-204"/>
+<text text-anchor="middle" x="151" y="-181.8" font-family="Times,serif" font-size="14.00" fill="#000000">Start</text>
+</g>
+<!-- Con_3 -->
+<g id="node2" class="node">
+<title>Con_3</title>
+<ellipse fill="none" stroke="#000000" cx="43" cy="-114" rx="27" ry="18"/>
+<text text-anchor="middle" x="43" y="-109.8" font-family="Times,serif" font-size="14.00" fill="#000000">#1</text>
+</g>
+<!-- Con_3&#45;&gt;Start2 -->
+<g id="edge1" class="edge">
+<title>Con_3-&gt;Start2</title>
+<path fill="none" stroke="#000000" stroke-dasharray="1,5" d="M62.3082,-126.8722C77.012,-136.6747 97.6668,-150.4445 115.3448,-162.2299"/>
+<polygon fill="#000000" stroke="#000000" points="113.4829,-165.195 123.7449,-167.8299 117.3658,-159.3707 113.4829,-165.195"/>
+<text text-anchor="middle" x="64.5318" y="-129.2722" font-family="Helvetica,sans-Serif" font-size="8.00" fill="#000000">0</text>
+</g>
+<!-- Con_4 -->
+<g id="node3" class="node">
+<title>Con_4</title>
+<ellipse fill="none" stroke="#000000" cx="115" cy="-114" rx="27" ry="18"/>
+<text text-anchor="middle" x="115" y="-109.8" font-family="Times,serif" font-size="14.00" fill="#000000">#2</text>
+</g>
+<!-- Con_4&#45;&gt;Start2 -->
+<g id="edge2" class="edge">
+<title>Con_4-&gt;Start2</title>
+<path fill="none" stroke="#000000" stroke-dasharray="1,5" d="M123.7146,-131.4292C127.8228,-139.6456 132.8196,-149.6392 137.4089,-158.8179"/>
+<polygon fill="#000000" stroke="#000000" points="134.387,-160.6004 141.9897,-167.9794 140.648,-157.4699 134.387,-160.6004"/>
+<text text-anchor="middle" x="121.491" y="-133.8292" font-family="Helvetica,sans-Serif" font-size="8.00" fill="#000000">0</text>
+</g>
+<!-- Con_6 -->
+<g id="node4" class="node">
+<title>Con_6</title>
+<ellipse fill="none" stroke="#000000" cx="259" cy="-114" rx="27" ry="18"/>
+<text text-anchor="middle" x="259" y="-109.8" font-family="Times,serif" font-size="14.00" fill="#000000">#5</text>
+</g>
+<!-- Con_6&#45;&gt;Start2 -->
+<g id="edge3" class="edge">
+<title>Con_6-&gt;Start2</title>
+<path fill="none" stroke="#000000" stroke-dasharray="1,5" d="M239.6918,-126.8722C224.988,-136.6747 204.3332,-150.4445 186.6552,-162.2299"/>
+<polygon fill="#000000" stroke="#000000" points="184.6342,-159.3707 178.2551,-167.8299 188.5171,-165.195 184.6342,-159.3707"/>
+<text text-anchor="middle" x="237.4682" y="-129.2722" font-family="Helvetica,sans-Serif" font-size="8.00" fill="#000000">0</text>
+</g>
+<!-- Con_8 -->
+<g id="node5" class="node">
+<title>Con_8</title>
+<ellipse fill="none" stroke="#000000" cx="187" cy="-114" rx="27" ry="18"/>
+<text text-anchor="middle" x="187" y="-109.8" font-family="Times,serif" font-size="14.00" fill="#000000">#6</text>
+</g>
+<!-- Con_8&#45;&gt;Start2 -->
+<g id="edge4" class="edge">
+<title>Con_8-&gt;Start2</title>
+<path fill="none" stroke="#000000" stroke-dasharray="1,5" d="M178.2854,-131.4292C174.1772,-139.6456 169.1804,-149.6392 164.5911,-158.8179"/>
+<polygon fill="#000000" stroke="#000000" points="161.352,-157.4699 160.0103,-167.9794 167.613,-160.6004 161.352,-157.4699"/>
+<text text-anchor="middle" x="176.0618" y="-133.8292" font-family="Helvetica,sans-Serif" font-size="8.00" fill="#000000">0</text>
+</g>
+<!-- Scope1_0 -->
+<g id="node6" class="node">
+<title>Scope1_0</title>
+<polygon fill="#00ffff" stroke="transparent" points="113,-31 113,-53 126,-53 126,-31 113,-31"/>
+<polygon fill="none" stroke="#000000" points="113,-31 113,-53 126,-53 126,-31 113,-31"/>
+<text text-anchor="start" x="116" y="-37.4" font-family="Times,serif" font-size="14.00" fill="#000000">0</text>
+<polygon fill="none" stroke="#000000" points="126,-31 126,-53 138,-53 138,-31 126,-31"/>
+<text text-anchor="start" x="128.8927" y="-37.4" font-family="Times,serif" font-size="14.00" fill="#000000">a</text>
+<polygon fill="none" stroke="#000000" points="138,-31 138,-53 151,-53 151,-31 138,-31"/>
+<text text-anchor="start" x="141" y="-37.4" font-family="Times,serif" font-size="14.00" fill="#000000">b</text>
+<polygon fill="none" stroke="#000000" points="151,-31 151,-53 163,-53 163,-31 151,-31"/>
+<text text-anchor="start" x="153.8927" y="-37.4" font-family="Times,serif" font-size="14.00" fill="#000000">c</text>
+</g>
+<!-- Scope1_0&#45;&gt;Con_3 -->
+<g id="edge5" class="edge">
+<title>Scope1_0:Scope1_0_a-&gt;Con_3</title>
+<path fill="none" stroke="#6495ed" stroke-dasharray="5,2" d="M132,-53C132,-81.2283 102.2249,-71.955 79,-88 75.8998,-90.1418 72.6712,-92.4134 69.4762,-94.6873"/>
+<polygon fill="#6495ed" stroke="#6495ed" points="67.2901,-91.9482 61.2087,-100.6239 71.373,-97.6342 67.2901,-91.9482"/>
+</g>
+<!-- Scope1_0&#45;&gt;Con_4 -->
+<g id="edge6" class="edge">
+<title>Scope1_0:Scope1_0_b-&gt;Con_4</title>
+<path fill="none" stroke="#6495ed" stroke-dasharray="5,2" d="M145,-53C145,-65.7791 139.6328,-78.661 133.4388,-89.2726"/>
+<polygon fill="#6495ed" stroke="#6495ed" points="130.3276,-87.6415 127.8968,-97.9538 136.2279,-91.4082 130.3276,-87.6415"/>
+</g>
+<!-- Scope1_0&#45;&gt;Con_8 -->
+<g id="edge7" class="edge">
+<title>Scope1_0:Scope1_0_c-&gt;Con_8</title>
+<path fill="none" stroke="#6495ed" stroke-dasharray="5,2" d="M157,-53C157,-65.7791 162.3672,-78.661 168.5612,-89.2726"/>
+<polygon fill="#6495ed" stroke="#6495ed" points="165.7721,-91.4082 174.1032,-97.9538 171.6724,-87.6415 165.7721,-91.4082"/>
+</g>
+<!-- Scope1_1 -->
+<g id="node7" class="node">
+<title>Scope1_1</title>
+<polygon fill="#00ffff" stroke="transparent" points="203,-31 203,-53 216,-53 216,-31 203,-31"/>
+<polygon fill="none" stroke="#000000" points="203,-31 203,-53 216,-53 216,-31 203,-31"/>
+<text text-anchor="start" x="206" y="-37.4" font-family="Times,serif" font-size="14.00" fill="#000000">1</text>
+<polygon fill="none" stroke="#000000" points="216,-31 216,-53 229,-53 229,-31 216,-31"/>
+<text text-anchor="start" x="219" y="-37.4" font-family="Times,serif" font-size="14.00" fill="#000000">b</text>
+</g>
+<!-- Scope1_1&#45;&gt;Con_6 -->
+<g id="edge8" class="edge">
+<title>Scope1_1:Scope1_1_b-&gt;Con_6</title>
+<path fill="none" stroke="#6495ed" stroke-dasharray="5,2" d="M223,-53C223,-66.7784 229.8964,-80.1812 237.6523,-90.8977"/>
+<polygon fill="#6495ed" stroke="#6495ed" points="235.0006,-93.1875 243.9413,-98.8721 240.497,-88.8528 235.0006,-93.1875"/>
+</g>
+</g>
+</svg> \ No newline at end of file
diff --git a/docs/chapter03/03-graph5.svg b/docs/chapter03/03-graph5.svg
new file mode 100644
index 00000000..48e69cb7
--- /dev/null
+++ b/docs/chapter03/03-graph5.svg
@@ -0,0 +1,127 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Generated by graphviz version 2.40.1 (20161225.0304)
+ -->
+<!-- Title: chapter03 Pages: 1 -->
+<svg width="310pt" height="228pt" viewBox="0.00 0.00 310.00 228.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 224)">
+<title>chapter03</title>
+<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-224 306,-224 306,4 -4,4"/>
+<g id="clust1" class="cluster">
+<title>cluster_Nodes</title>
+<polygon fill="none" stroke="#000000" points="8,-88 8,-212 294,-212 294,-88 8,-88"/>
+</g>
+<g id="clust2" class="cluster">
+<title>cluster_Scope1_0</title>
+<polygon fill="none" stroke="#000000" points="97,-8 97,-76 259,-76 259,-8 97,-8"/>
+</g>
+<g id="clust3" class="cluster">
+<title>cluster_Scope1_1</title>
+<polygon fill="none" stroke="#000000" points="181,-16 181,-68 251,-68 251,-16 181,-16"/>
+</g>
+<!-- Start2 -->
+<g id="node1" class="node">
+<title>Start2</title>
+<polygon fill="#ffff00" stroke="#000000" points="178,-204 124,-204 124,-168 178,-168 178,-204"/>
+<text text-anchor="middle" x="151" y="-181.8" font-family="Times,serif" font-size="14.00" fill="#000000">Start</text>
+</g>
+<!-- Con_3 -->
+<g id="node2" class="node">
+<title>Con_3</title>
+<ellipse fill="none" stroke="#000000" cx="43" cy="-114" rx="27" ry="18"/>
+<text text-anchor="middle" x="43" y="-109.8" font-family="Times,serif" font-size="14.00" fill="#000000">#1</text>
+</g>
+<!-- Con_3&#45;&gt;Start2 -->
+<g id="edge1" class="edge">
+<title>Con_3-&gt;Start2</title>
+<path fill="none" stroke="#000000" stroke-dasharray="1,5" d="M62.3082,-126.8722C77.012,-136.6747 97.6668,-150.4445 115.3448,-162.2299"/>
+<polygon fill="#000000" stroke="#000000" points="113.4829,-165.195 123.7449,-167.8299 117.3658,-159.3707 113.4829,-165.195"/>
+<text text-anchor="middle" x="64.5318" y="-129.2722" font-family="Helvetica,sans-Serif" font-size="8.00" fill="#000000">0</text>
+</g>
+<!-- Con_4 -->
+<g id="node3" class="node">
+<title>Con_4</title>
+<ellipse fill="none" stroke="#000000" cx="115" cy="-114" rx="27" ry="18"/>
+<text text-anchor="middle" x="115" y="-109.8" font-family="Times,serif" font-size="14.00" fill="#000000">#2</text>
+</g>
+<!-- Con_4&#45;&gt;Start2 -->
+<g id="edge2" class="edge">
+<title>Con_4-&gt;Start2</title>
+<path fill="none" stroke="#000000" stroke-dasharray="1,5" d="M123.7146,-131.4292C127.8228,-139.6456 132.8196,-149.6392 137.4089,-158.8179"/>
+<polygon fill="#000000" stroke="#000000" points="134.387,-160.6004 141.9897,-167.9794 140.648,-157.4699 134.387,-160.6004"/>
+<text text-anchor="middle" x="121.491" y="-133.8292" font-family="Helvetica,sans-Serif" font-size="8.00" fill="#000000">0</text>
+</g>
+<!-- Con_9 -->
+<g id="node4" class="node">
+<title>Con_9</title>
+<ellipse fill="none" stroke="#000000" cx="259" cy="-114" rx="27" ry="18"/>
+<text text-anchor="middle" x="259" y="-109.8" font-family="Times,serif" font-size="14.00" fill="#000000">#6</text>
+</g>
+<!-- Con_9&#45;&gt;Start2 -->
+<g id="edge3" class="edge">
+<title>Con_9-&gt;Start2</title>
+<path fill="none" stroke="#000000" stroke-dasharray="1,5" d="M239.6918,-126.8722C224.988,-136.6747 204.3332,-150.4445 186.6552,-162.2299"/>
+<polygon fill="#000000" stroke="#000000" points="184.6342,-159.3707 178.2551,-167.8299 188.5171,-165.195 184.6342,-159.3707"/>
+<text text-anchor="middle" x="237.4682" y="-129.2722" font-family="Helvetica,sans-Serif" font-size="8.00" fill="#000000">0</text>
+</g>
+<!-- Con_11 -->
+<g id="node5" class="node">
+<title>Con_11</title>
+<ellipse fill="none" stroke="#000000" cx="187" cy="-114" rx="27" ry="18"/>
+<text text-anchor="middle" x="187" y="-109.8" font-family="Times,serif" font-size="14.00" fill="#000000">#7</text>
+</g>
+<!-- Con_11&#45;&gt;Start2 -->
+<g id="edge4" class="edge">
+<title>Con_11-&gt;Start2</title>
+<path fill="none" stroke="#000000" stroke-dasharray="1,5" d="M178.2854,-131.4292C174.1772,-139.6456 169.1804,-149.6392 164.5911,-158.8179"/>
+<polygon fill="#000000" stroke="#000000" points="161.352,-157.4699 160.0103,-167.9794 167.613,-160.6004 161.352,-157.4699"/>
+<text text-anchor="middle" x="176.0618" y="-133.8292" font-family="Helvetica,sans-Serif" font-size="8.00" fill="#000000">0</text>
+</g>
+<!-- Scope1_0 -->
+<g id="node6" class="node">
+<title>Scope1_0</title>
+<polygon fill="#00ffff" stroke="transparent" points="113,-31 113,-53 126,-53 126,-31 113,-31"/>
+<polygon fill="none" stroke="#000000" points="113,-31 113,-53 126,-53 126,-31 113,-31"/>
+<text text-anchor="start" x="116" y="-37.4" font-family="Times,serif" font-size="14.00" fill="#000000">0</text>
+<polygon fill="none" stroke="#000000" points="126,-31 126,-53 138,-53 138,-31 126,-31"/>
+<text text-anchor="start" x="128.8927" y="-37.4" font-family="Times,serif" font-size="14.00" fill="#000000">a</text>
+<polygon fill="none" stroke="#000000" points="138,-31 138,-53 151,-53 151,-31 138,-31"/>
+<text text-anchor="start" x="141" y="-37.4" font-family="Times,serif" font-size="14.00" fill="#000000">b</text>
+<polygon fill="none" stroke="#000000" points="151,-31 151,-53 163,-53 163,-31 151,-31"/>
+<text text-anchor="start" x="153.8927" y="-37.4" font-family="Times,serif" font-size="14.00" fill="#000000">c</text>
+</g>
+<!-- Scope1_0&#45;&gt;Con_3 -->
+<g id="edge5" class="edge">
+<title>Scope1_0:Scope1_0_a-&gt;Con_3</title>
+<path fill="none" stroke="#6495ed" stroke-dasharray="5,2" d="M132,-53C132,-81.2283 102.2249,-71.955 79,-88 75.8998,-90.1418 72.6712,-92.4134 69.4762,-94.6873"/>
+<polygon fill="#6495ed" stroke="#6495ed" points="67.2901,-91.9482 61.2087,-100.6239 71.373,-97.6342 67.2901,-91.9482"/>
+</g>
+<!-- Scope1_0&#45;&gt;Con_4 -->
+<g id="edge6" class="edge">
+<title>Scope1_0:Scope1_0_b-&gt;Con_4</title>
+<path fill="none" stroke="#6495ed" stroke-dasharray="5,2" d="M145,-53C145,-65.7791 139.6328,-78.661 133.4388,-89.2726"/>
+<polygon fill="#6495ed" stroke="#6495ed" points="130.3276,-87.6415 127.8968,-97.9538 136.2279,-91.4082 130.3276,-87.6415"/>
+</g>
+<!-- Scope1_0&#45;&gt;Con_11 -->
+<g id="edge7" class="edge">
+<title>Scope1_0:Scope1_0_c-&gt;Con_11</title>
+<path fill="none" stroke="#6495ed" stroke-dasharray="5,2" d="M157,-53C157,-65.7791 162.3672,-78.661 168.5612,-89.2726"/>
+<polygon fill="#6495ed" stroke="#6495ed" points="165.7721,-91.4082 174.1032,-97.9538 171.6724,-87.6415 165.7721,-91.4082"/>
+</g>
+<!-- Scope1_1 -->
+<g id="node7" class="node">
+<title>Scope1_1</title>
+<polygon fill="#00ffff" stroke="transparent" points="204,-31 204,-53 217,-53 217,-31 204,-31"/>
+<polygon fill="none" stroke="#000000" points="204,-31 204,-53 217,-53 217,-31 204,-31"/>
+<text text-anchor="start" x="207" y="-37.4" font-family="Times,serif" font-size="14.00" fill="#000000">1</text>
+<polygon fill="none" stroke="#000000" points="217,-31 217,-53 229,-53 229,-31 217,-31"/>
+<text text-anchor="start" x="219.8927" y="-37.4" font-family="Times,serif" font-size="14.00" fill="#000000">e</text>
+</g>
+<!-- Scope1_1&#45;&gt;Con_9 -->
+<g id="edge8" class="edge">
+<title>Scope1_1:Scope1_1_e-&gt;Con_9</title>
+<path fill="none" stroke="#6495ed" stroke-dasharray="5,2" d="M223,-53C223,-66.7784 229.8964,-80.1812 237.6523,-90.8977"/>
+<polygon fill="#6495ed" stroke="#6495ed" points="235.0006,-93.1875 243.9413,-98.8721 240.497,-88.8528 235.0006,-93.1875"/>
+</g>
+</g>
+</svg> \ No newline at end of file
diff --git a/docs/chapter03/Makefile b/docs/chapter03/Makefile
new file mode 100644
index 00000000..12659b8f
--- /dev/null
+++ b/docs/chapter03/Makefile
@@ -0,0 +1,12 @@
+GV := $(wildcard *.gv)
+SVG := $(patsubst %.gv,%.svg,$(GV))
+
+.PHONY: all
+all: $(SVG)
+
+%.svg: %.gv
+ dot -Tsvg $< > $@
+
+.PHONY: clean
+clean:
+ @rm -f $(SVG)
diff --git a/docs/chapter03/README.md b/docs/chapter03/README.md
new file mode 100644
index 00000000..d26b2462
--- /dev/null
+++ b/docs/chapter03/README.md
@@ -0,0 +1,197 @@
+# Chapter 3: Variable Declarations
+
+# Table of Contents
+
+1. [Extensions to Intermediate Representation](#extensions-to-intermediate-representation)
+2. [Symbol Tables](#symbol-tables)
+3. [ScopeNode](#scopenode)
+4. [Demonstration](#demonstration)
+5. [Identification of Basic Blocks in SoN graph](#identification-of-basic-blocks-in-son-graph)
+6. [Enabling peephole optimizations](#enabling-peephole-optimizations)
+
+You can also read [this chapter](https://github.com/SeaOfNodes/Simple/tree/linear-chapter03) in a linear Git revision history on the [linear](https://github.com/SeaOfNodes/Simple/tree/linear) branch and [compare](https://github.com/SeaOfNodes/Simple/compare/linear-chapter02...linear-chapter03) it to the previous chapter.
+
+In this chapter we extend the language grammar to allow variable declarations. This allows us to write:
+
+```
+int a=1;
+int b=2;
+int c=0;
+{
+ int b=3;
+ c=a+b;
+}
+return c;
+```
+
+Here is the [complete language grammar](03-grammar.md) for this chapter.
+
+
+## Extensions to Intermediate Representation
+
+To recap, our list of Nodes are:
+
+| Node Name | Type | Description | Inputs | Value |
+|-----------|---------|------------------------------------|------------------------------------------------------------------|-------------------------------------------------------|
+| Start | Control | Start of function | None | None for now as we do not have function arguments yet |
+| Return | Control | End of function | Predecessor control node, Data node value | Return value of the function |
+| Constant | Data | Constants such as integer literals | None, however Start node is set as input to enable graph walking | Value of the constant |
+| Add | Data | Add two values | Two data nodes, values are added, order not important | Result of the add operation |
+| Sub | Data | Subtract a value from another | Two data nodes, values are subtracted, order matters | Result of the subtract |
+| Mul | Data | Multiply two values | Two data nodes, values are multiplied, order not important | Result of the multiply |
+| Div | Data | Divide a value by another | Two data nodes, values are divided, order matters | Result of the division |
+| Minus | Data | Negate a value | One data node, value is negated | Result of the unary minus |
+
+In this chapter we introduce:
+
+| Node Name | Type | Description | Inputs | Value |
+|-----------|--------------|--------------------------------|---------------------------------|-------|
+| Scope | Symbol Table | Represents scopes in the graph | All nodes that define variables | None |
+
+
+## Symbol Tables
+
+To support variable declarations and lexical scopes, we introduce symbol tables
+in the parser. A symbol table maps names to nodes.
+
+We maintain a *stack* of symbol tables.
+When a new lexical scope is created we push a new symbol table to the stack;
+when scope exits the topmost symbol table is popped from the stack.
+
+Declaring a name adds it to the current symbol table. If a name is assigned
+to, then its mapping in the most recent symbol table is updated. If a name is
+accessed, its mapping is looked up in the symbol tables. The lookup goes up
+the stack of symbol tables, in lexical order.
+
+## ScopeNode
+
+A ScopeNode encapsulates the stack of symbol tables that are used to implement lexical scopes.
+
+* The nodes referenced by the names in a lexical scope become inputs to the ScopeNode; this makes ScopeNode a user of these values, thus keeping them alive while a particular lexical scope is alive.
+ When the lexical scope ends, those inputs are removed. This is crucial because peepholes will remove dead Nodes and every new Node is effectively dead at the instance of creation without such a reference.
+* In [Chapter 5](../chapter05/README.md) when we implement branches, the ScopeNode gets duplicated at a branch point and then gets merged when the branch joins. This allows
+ the names to evolve in each branch independently. At the merge point names that have diverged require a Phi node.
+* In [Chapter 7](../chapter07/README.md) additional logic is deployed for handling Phis from back edges.
+* The ScopeNode is used to track some other values such as the Control token starting from [Chapter 4](../chapter04/README.md), and Aliases starting from [Chapter 10](../chapter10/README.md). Special name bindings are used
+ for these, and each name is tracked across branches and then merged at merge points.
+* In [Chapter 10](../chapter10/README.md) the ScopeNode is enhanced to also maintain the declared type for each name.
+
+From an implementation standpoint, each symbol table is represented as a `HashMap<String,Integer>`, where the `String` is the variable name, and the `Integer` is an index into the inputs of the
+ScopeNode. To access the Node associated with a name, first the symbol table is consulted, and then the ScopeNode's inputs to find the required Node.
+The stack of symbol tables is represented as `Stack<HashMap<String,Integer>>`.
+
+When a lexical scope is exited, we not only pop the symbol table representing the
+scope from the stack, but also remove the relevant input nodes. If the variable's expression
+only exists for the Scope mapping (e.g., "just in case" the Parser parses code
+that uses the variable) this is when the expression dies:
+```
+ int a=1;
+ {
+ int b=a*a*a;
+ } // When this scope closes & ends, b (and the cube of a) dies
+ return a;
+```
+
+
+In the visualization, we show the ScopeNode in a separate box running
+underneath the main IR graph; the stack of symbol tables is shown inside the
+box. We show the edge from each variable in the symbol table to the defining
+Node in the graph.
+
+The ScopeNode is neither a Data Node nor a Control Node; it really is a utility for maintaining symbol tables, name lookups, plays a crucial role in deciding where Phi nodes are required.
+Representing it as a Node allows us to leverage the Sea of Nodes def-use architecture to maintain liveness of values in scope.
+
+A ScopeNode has no outputs.
+
+## Demonstration
+
+We show the output from following code.
+
+```
+01 int a=1;
+02 int b=2;
+03 int c=0;
+04 {
+05 int b=3;
+07 c=a+b;
+08 }
+09 return c;
+```
+
+* When we start parsing above, we start with a symbol table (at level 0).
+The variables `a`, `b`, and `c` are registered in this table.
+* On line 4, we start a nested scope. At this point, a new symbol table is pushed (at level 1).
+* On line 5, a variable `b` is declared. `b` is registered in the symbol table at level 1. This then
+hides the variable with the same name on line 2.
+* On line 7, we update the variable `c`. Variable lookup will find it in the symbol table at level 0.
+The node graph is shown below (note that peephole opts are switched off here so that we can
+see the graph as its initially constructed).
+
+![Graph1](./03-graph1.svg)
+
+The diagram shows the ScopeNode and the symbol tables in the bottom cluster.
+Each table is annotated by its scope level, and shows the variables defined in that scope.
+
+* When we exit the nested scope on line 8, the symbol table at level 1 is popped.
+* At line 9, our graph looks like this:
+
+![Graph2](./03-graph2.svg)
+
+As we see, only 1 symbol table is present at this point.
+
+We can also have multiple scopes at the same level during the execution of the program,
+but only one will be active at a time because the symbol table can only hold one symbol table
+for each scope level.
+
+For example:
+```
+01 int a=1;
+02 int b=2;
+03 int c=0;
+04 {
+05 int b=5;
+06 c=a+b;
+08 }
+09 {
+10 int e=6;
+11 c = a+e;
+13 }
+14 return c;
+```
+Here both scopes starting from `(04-08)` and `(09-13)` are at the same level:
+```java
+public final Stack<HashMap<String, Integer>> _scopes;
+```
+The `_scopes` stack holds nested scopes, with index 0 representing the highest (global)
+scope and deeper indices representing more nested scopes.
+Popping returns the current scope and moves to the outer one.
+There is a direct one-to-one mapping between each index and its corresponding scope.
+
+The first nested scope(04-08):
+
+![Graph4](./03-graph4.svg)
+
+The second nested scope(09-13):
+
+![Graph5](./03-graph5.svg)
+
+ - In both cases the index which represents the deepness of the scope is 1.
+## Enabling peephole optimizations
+
+Once we enable peephole optimizations, the parser is able to reduce all the expressions down to a
+constant. This is illustrated nicely below.
+
+```
+01 int x0=1;
+02 int y0=2;
+03 int x1=3;
+04 int y1=4;
+05 return (x0-x1)*(x0-x1) + (y0-y1)*(y0-y1);
+```
+
+The graph for above, is displayed below.
+
+![Graph2](./03-graph3.svg)
+
+The return node has the constant `8` as its data value! When the parsing ends
+and the scope at level 0 is removed, only the `return 8` remains.