From 8b8cdf8873b30fd21f9012a479a42809c079eb42 Mon Sep 17 00:00:00 2001 From: dibyendumajumdar Date: Sun, 17 Sep 2023 14:06:27 +0100 Subject: Revise grammar for chapter 1. Start writing up Chapter 1. --- chapter01/docs/01-grammar.md | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'chapter01/docs') diff --git a/chapter01/docs/01-grammar.md b/chapter01/docs/01-grammar.md index 92ed7357..63816e2e 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 + : [0-9]+ + ; ``` \ No newline at end of file -- cgit v1.2.3 From 00af1bb88668791e9da5d43c921e38348beec421 Mon Sep 17 00:00:00 2001 From: dibyendumajumdar Date: Sun, 17 Sep 2023 17:13:01 +0100 Subject: Revised based on feedback Added descriptions of the nodes. --- chapter01/docs/01-grammar.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'chapter01/docs') diff --git a/chapter01/docs/01-grammar.md b/chapter01/docs/01-grammar.md index 63816e2e..7c5cb57a 100644 --- a/chapter01/docs/01-grammar.md +++ b/chapter01/docs/01-grammar.md @@ -20,6 +20,6 @@ primaryExpression ; INTEGER_LITERAL - : [0-9]+ + : [1-9][0-0]* ; ``` \ No newline at end of file -- cgit v1.2.3 From e1ca5e63053d5d67fb77b35c773bb81ac502a58c Mon Sep 17 00:00:00 2001 From: dibyendumajumdar Date: Sun, 17 Sep 2023 17:21:39 +0100 Subject: Fix typos --- chapter01/docs/01-grammar.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'chapter01/docs') diff --git a/chapter01/docs/01-grammar.md b/chapter01/docs/01-grammar.md index 7c5cb57a..cf947dfc 100644 --- a/chapter01/docs/01-grammar.md +++ b/chapter01/docs/01-grammar.md @@ -20,6 +20,6 @@ primaryExpression ; INTEGER_LITERAL - : [1-9][0-0]* + : [1-9][0-9]* ; ``` \ No newline at end of file -- cgit v1.2.3 From ab6746dddee6175a68df2b34c147751e267324da Mon Sep 17 00:00:00 2001 From: dibyendumajumdar Date: Sun, 17 Sep 2023 19:21:12 +0100 Subject: Add diagram --- chapter01/docs/02-graph.gv | 29 ++++++++++++++++++++++++++ chapter01/docs/02-graph.svg | 51 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 chapter01/docs/02-graph.gv create mode 100644 chapter01/docs/02-graph.svg (limited to 'chapter01/docs') diff --git a/chapter01/docs/02-graph.gv b/chapter01/docs/02-graph.gv new file mode 100644 index 00000000..a47c23fe --- /dev/null +++ b/chapter01/docs/02-graph.gv @@ -0,0 +1,29 @@ +digraph chapter01 +{ + start [shape=none, label=< + + + + + + + +
Inputs
Start
+ >]; + constant [label="Constant 1"]; + return [shape=none, label=< + + + + + + + + + +
Inputs01
Return
+ >]; + constant -> return:input1; + edge [color=red]; + start -> return:input0 [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..1ced4870 --- /dev/null +++ b/chapter01/docs/02-graph.svg @@ -0,0 +1,51 @@ + + + + + + +chapter01 + + + +start + +Inputs + +Start + + + +return + +Inputs + +0 + +1 + +Return + + + +start->return:input0 + + + + + +constant + +Constant 1 + + + +constant->return:input1 + + + + + -- cgit v1.2.3 From 7ec5a9425c7585a67dc834cfb762470e86695b41 Mon Sep 17 00:00:00 2001 From: dibyendumajumdar Date: Sun, 17 Sep 2023 20:53:53 +0100 Subject: Revise text and update diagram. Remove the detail re inputs to a node from the diagram. --- chapter01/docs/02-graph.gv | 28 ++++------------------------ chapter01/docs/02-graph.svg | 40 ++++++++++++++++------------------------ 2 files changed, 20 insertions(+), 48 deletions(-) (limited to 'chapter01/docs') diff --git a/chapter01/docs/02-graph.gv b/chapter01/docs/02-graph.gv index a47c23fe..40181544 100644 --- a/chapter01/docs/02-graph.gv +++ b/chapter01/docs/02-graph.gv @@ -1,29 +1,9 @@ digraph chapter01 { - start [shape=none, label=< - - - - - - - -
Inputs
Start
- >]; + start [shape=box, label="Start"]; constant [label="Constant 1"]; - return [shape=none, label=< - - - - - - - - - -
Inputs01
Return
- >]; - constant -> return:input1; + return [shape=box, label="Return"]; + constant -> return; edge [color=red]; - start -> return:input0 [style=bold]; + start -> return [style=bold]; } \ No newline at end of file diff --git a/chapter01/docs/02-graph.svg b/chapter01/docs/02-graph.svg index 1ced4870..fbf92d7d 100644 --- a/chapter01/docs/02-graph.svg +++ b/chapter01/docs/02-graph.svg @@ -4,48 +4,40 @@ - - + + chapter01 - + start - -Inputs - -Start + +Start return - -Inputs - -0 - -1 - -Return + +Return -start->return:input0 - - +start->return + + constant - -Constant 1 + +Constant 1 -constant->return:input1 - - +constant->return + + -- cgit v1.2.3