summaryrefslogtreecommitdiff
path: root/chapter01/docs/01-grammar.md
diff options
context:
space:
mode:
authordibyendumajumdar <mobile@majumdar.org.uk>2023-09-17 14:06:27 +0100
committerdibyendumajumdar <mobile@majumdar.org.uk>2023-09-17 14:06:27 +0100
commit8b8cdf8873b30fd21f9012a479a42809c079eb42 (patch)
tree5a83da4a7dd7a28044ff668b1e556a2f25ec3826 /chapter01/docs/01-grammar.md
parentdbd9798602c3b80bc00c93c797b942dcb0e234c1 (diff)
downloadSimple-8b8cdf8873b30fd21f9012a479a42809c079eb42.tar.gz
Simple-8b8cdf8873b30fd21f9012a479a42809c079eb42.zip
Revise grammar for chapter 1.
Start writing up Chapter 1.
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..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