summaryrefslogtreecommitdiff
path: root/chapter01/docs
diff options
context:
space:
mode:
authorDibyendu Majumdar <dibyendumajumdar@users.noreply.github.com>2023-09-19 23:48:34 +0100
committerGitHub <noreply@github.com>2023-09-19 23:48:34 +0100
commit62bfd0d619b28892152a7d89639f3437bc9df573 (patch)
tree0e628f6a331a0c7e3b56424021243535019f7784 /chapter01/docs
parentee3a2f571897b23caecfe9cfe4f5e4338007f885 (diff)
parentcecb62d847da7dc937b52857ae2fd4b41af98a7c (diff)
downloadSimple-62bfd0d619b28892152a7d89639f3437bc9df573.tar.gz
Simple-62bfd0d619b28892152a7d89639f3437bc9df573.zip
Merge pull request #3 from dibyendumajumdar/main
Chapter 1 implementation
Diffstat (limited to 'chapter01/docs')
-rw-r--r--chapter01/docs/01-grammar.md30
-rw-r--r--chapter01/docs/02-graph.gv9
-rw-r--r--chapter01/docs/02-graph.svg43
3 files changed, 60 insertions, 22 deletions
diff --git a/chapter01/docs/01-grammar.md b/chapter01/docs/01-grammar.md
index 92ed7357..cf947dfc 100644
--- a/chapter01/docs/01-grammar.md
+++ b/chapter01/docs/01-grammar.md
@@ -4,36 +4,22 @@
grammar SimpleLanguage;
program
- : declaration* statement+ EOF
- ;
-
-declaration
- : type IDENTIFIER ';'
- ;
-
-type
- : 'int'
+ : statement EOF
;
statement
- : 'if' '(' expression ')' statement
- | 'if' '(' expression ')' statement 'else' statement
- | 'while' '(' expression ')' statement
- | IDENTIFIER '=' expression ';'
- | '{' declaration* statement+ '}'
- | 'break' ';'
+ : 'return' expression ';'
;
expression
- : primaryExpression # PrimaryExpression_
- | expression ('*' | '/' ) expression # ArithmeticOrLogicalExpression
- | expression ('+' | '-') expression # ArithmeticOrLogicalExpression
+ : primaryExpression
;
primaryExpression
- :
- | INTEGER_LITERAL
- | IDENTIFIER
- | '(' expression ')'
+ : INTEGER_LITERAL
;
+
+INTEGER_LITERAL
+ : [1-9][0-9]*
+ ;
``` \ No newline at end of file
diff --git a/chapter01/docs/02-graph.gv b/chapter01/docs/02-graph.gv
new file mode 100644
index 00000000..40181544
--- /dev/null
+++ b/chapter01/docs/02-graph.gv
@@ -0,0 +1,9 @@
+digraph chapter01
+{
+ start [shape=box, label="Start"];
+ constant [label="Constant 1"];
+ return [shape=box, label="Return"];
+ constant -> return;
+ edge [color=red];
+ start -> return [style=bold];
+} \ No newline at end of file
diff --git a/chapter01/docs/02-graph.svg b/chapter01/docs/02-graph.svg
new file mode 100644
index 00000000..fbf92d7d
--- /dev/null
+++ b/chapter01/docs/02-graph.svg
@@ -0,0 +1,43 @@
+<?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: chapter01 Pages: 1 -->
+<svg width="204pt" height="116pt"
+ viewBox="0.00 0.00 203.74 116.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 112)">
+<title>chapter01</title>
+<polygon fill="white" stroke="transparent" points="-4,4 -4,-112 199.74,-112 199.74,4 -4,4"/>
+<!-- start -->
+<g id="node1" class="node">
+<title>start</title>
+<polygon fill="none" stroke="black" points="54,-108 0,-108 0,-72 54,-72 54,-108"/>
+<text text-anchor="middle" x="27" y="-86.3" font-family="Times,serif" font-size="14.00">Start</text>
+</g>
+<!-- return -->
+<g id="node3" class="node">
+<title>return</title>
+<polygon fill="none" stroke="black" points="113,-36 47,-36 47,0 113,0 113,-36"/>
+<text text-anchor="middle" x="80" y="-14.3" font-family="Times,serif" font-size="14.00">Return</text>
+</g>
+<!-- start&#45;&gt;return -->
+<g id="edge2" class="edge">
+<title>start&#45;&gt;return</title>
+<path fill="none" stroke="red" stroke-width="2" d="M40.1,-71.7C46.39,-63.39 54.05,-53.28 60.96,-44.14"/>
+<polygon fill="red" stroke="red" stroke-width="2" points="63.8,-46.19 67.05,-36.1 58.22,-41.96 63.8,-46.19"/>
+</g>
+<!-- constant -->
+<g id="node2" class="node">
+<title>constant</title>
+<ellipse fill="none" stroke="black" cx="134" cy="-90" rx="61.99" ry="18"/>
+<text text-anchor="middle" x="134" y="-86.3" font-family="Times,serif" font-size="14.00">Constant 1</text>
+</g>
+<!-- constant&#45;&gt;return -->
+<g id="edge1" class="edge">
+<title>constant&#45;&gt;return</title>
+<path fill="none" stroke="black" d="M120.93,-72.05C114.52,-63.75 106.68,-53.58 99.58,-44.38"/>
+<polygon fill="black" stroke="black" points="102.21,-42.06 93.33,-36.28 96.66,-46.33 102.21,-42.06"/>
+</g>
+</g>
+</svg>