summaryrefslogtreecommitdiff
path: root/chapter01/docs/01-grammar.md
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/01-grammar.md
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/01-grammar.md')
-rw-r--r--chapter01/docs/01-grammar.md30
1 files changed, 8 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