summaryrefslogtreecommitdiff
path: root/chapter01/docs
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2023-09-07 14:32:31 -0700
committerGitHub <noreply@github.com>2023-09-07 14:32:31 -0700
commitee3a2f571897b23caecfe9cfe4f5e4338007f885 (patch)
tree5a32a60e3070347c99b4ee6fa572533f90d77085 /chapter01/docs
parent1571eeeb41c3af5cc2da23ce4edbc69cf53bd383 (diff)
parentdbd9798602c3b80bc00c93c797b942dcb0e234c1 (diff)
downloadSimple-ee3a2f571897b23caecfe9cfe4f5e4338007f885.tar.gz
Simple-ee3a2f571897b23caecfe9cfe4f5e4338007f885.zip
Merge pull request #2 from dibyendumajumdar/main
Initial framework for the project
Diffstat (limited to 'chapter01/docs')
-rw-r--r--chapter01/docs/01-grammar.md39
1 files changed, 39 insertions, 0 deletions
diff --git a/chapter01/docs/01-grammar.md b/chapter01/docs/01-grammar.md
new file mode 100644
index 00000000..92ed7357
--- /dev/null
+++ b/chapter01/docs/01-grammar.md
@@ -0,0 +1,39 @@
+# Grammar for Chapter 1
+
+```antlrv4
+grammar SimpleLanguage;
+
+program
+ : declaration* statement+ EOF
+ ;
+
+declaration
+ : type IDENTIFIER ';'
+ ;
+
+type
+ : 'int'
+ ;
+
+statement
+ : 'if' '(' expression ')' statement
+ | 'if' '(' expression ')' statement 'else' statement
+ | 'while' '(' expression ')' statement
+ | IDENTIFIER '=' expression ';'
+ | '{' declaration* statement+ '}'
+ | 'break' ';'
+ ;
+
+expression
+ : primaryExpression # PrimaryExpression_
+ | expression ('*' | '/' ) expression # ArithmeticOrLogicalExpression
+ | expression ('+' | '-') expression # ArithmeticOrLogicalExpression
+ ;
+
+primaryExpression
+ :
+ | INTEGER_LITERAL
+ | IDENTIFIER
+ | '(' expression ')'
+ ;
+``` \ No newline at end of file