diff options
| author | dibyendumajumdar <mobile@majumdar.org.uk> | 2023-08-25 23:26:23 +0100 |
|---|---|---|
| committer | dibyendumajumdar <mobile@majumdar.org.uk> | 2023-08-25 23:26:23 +0100 |
| commit | b8f815a16ebad6675b6305d623196a8210145b75 (patch) | |
| tree | 83ac01235150a525db6c8d73b56e0792c75d5408 /chapter01/docs | |
| parent | 9a2ab9bb803aa4da2a6007cc2e945d6bc1fe0b39 (diff) | |
| download | Simple-b8f815a16ebad6675b6305d623196a8210145b75.tar.gz Simple-b8f815a16ebad6675b6305d623196a8210145b75.zip | |
Added a grammar definition for chapter 01.
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 index e69de29b..92ed7357 100644 --- a/chapter01/docs/01-grammar.md +++ 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 |
