diff options
| author | Thalia Archibald <thalia@archibald.dev> | 2024-07-01 08:42:23 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-01 08:42:23 -0700 |
| commit | d6442ce5d00b9bea52d366ff4d6ae8c03b84aabb (patch) | |
| tree | f74a567beac80bbe4c7dfb8cecac853d7ba6ec80 /chapter11/docs/11-grammar.md | |
| parent | 383a1b7c38d444ea8a1b8643b0be2608a6f8e84d (diff) | |
| download | Simple-d6442ce5d00b9bea52d366ff4d6ae8c03b84aabb.tar.gz Simple-d6442ce5d00b9bea52d366ff4d6ae8c03b84aabb.zip | |
Fix grammar and forward-port minor changes (#91)
* Backport test exception handling to chapter 1
* Add unary ! to chapter 10 and 11 grammars
* Lex { } ! as punctuation
* Forward-port format whitespace
* Forward-port test organization
* Forward-port replace build-graphs.sh with Makefile
* Add chapter title to chapter 11
Diffstat (limited to 'chapter11/docs/11-grammar.md')
| -rw-r--r-- | chapter11/docs/11-grammar.md | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/chapter11/docs/11-grammar.md b/chapter11/docs/11-grammar.md index 0aaf0619..9370024e 100644 --- a/chapter11/docs/11-grammar.md +++ b/chapter11/docs/11-grammar.md @@ -11,7 +11,7 @@ statement : returnStatement | structDeclaration | declStatement - | blockStatment + | blockStatment | expressionStatement | ifStatement | whileStatement @@ -26,7 +26,7 @@ field fields : field+ - ; + ; structDeclaration : 'struct' IDENTIFIER '{' fields '}' @@ -39,10 +39,10 @@ whileStatement breakStatement : 'break' ';' ; - + continueStatement : 'continue' ';' - ; + ; ifStatement : 'if' '(' expression ')' statement ('else' statement)? @@ -77,26 +77,27 @@ returnStatement expression : comparisonExpression ; - + comparisonExpression : additiveExpression (('==' | '!='| '>'| '<'| '>='| '<=') additiveExpression)* ; - + additiveExpression - : multiplicativeExpression (('+' | '-') multiplicativeExpression)* + : multiplicativeExpression (('+' | '-') multiplicativeExpression)* ; - + multiplicativeExpression : unaryExpression (('*' | '/') unaryExpression)* ; unaryExpression : ('-') unaryExpression + | '!' unaryExpression | primaryExpression ; newExpression - : 'new' IDENTIFIER + : 'new' IDENTIFIER ; fieldExpression @@ -118,11 +119,11 @@ INTEGER_LITERAL : [1-9][0-9]* | [0] ; - + IDENTIFIER : NON_DIGIT (NON_DIGIT | DIGIT)* ; - + NON_DIGIT: [a-zA-Z_]; DEC_DIGIT: [0-9]; -```
\ No newline at end of file +``` |
