diff options
| author | dibyendumajumdar <mobile@majumdar.org.uk> | 2023-09-17 14:06:27 +0100 |
|---|---|---|
| committer | dibyendumajumdar <mobile@majumdar.org.uk> | 2023-09-17 14:06:27 +0100 |
| commit | 8b8cdf8873b30fd21f9012a479a42809c079eb42 (patch) | |
| tree | 5a83da4a7dd7a28044ff668b1e556a2f25ec3826 /chapter01/docs | |
| parent | dbd9798602c3b80bc00c93c797b942dcb0e234c1 (diff) | |
| download | Simple-8b8cdf8873b30fd21f9012a479a42809c079eb42.tar.gz Simple-8b8cdf8873b30fd21f9012a479a42809c079eb42.zip | |
Revise grammar for chapter 1.
Start writing up Chapter 1.
Diffstat (limited to 'chapter01/docs')
| -rw-r--r-- | chapter01/docs/01-grammar.md | 30 |
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 |
