diff options
| author | Cliff Click <cliffc@acm.org> | 2023-09-07 14:32:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-07 14:32:31 -0700 |
| commit | ee3a2f571897b23caecfe9cfe4f5e4338007f885 (patch) | |
| tree | 5a32a60e3070347c99b4ee6fa572533f90d77085 /chapter01/docs | |
| parent | 1571eeeb41c3af5cc2da23ce4edbc69cf53bd383 (diff) | |
| parent | dbd9798602c3b80bc00c93c797b942dcb0e234c1 (diff) | |
| download | Simple-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.md | 39 |
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 |
