summaryrefslogtreecommitdiff
path: root/chapter13
diff options
context:
space:
mode:
authorThalia Archibald <thalia@archibald.dev>2024-08-05 16:31:29 -0700
committerDibyendu Majumdar <dibyendumajumdar@users.noreply.github.com>2024-08-06 00:50:58 +0100
commit49af186140611daa9c840189139b59c854f1889c (patch)
treee979746419d3646f5fde7d525c14966eb752fd22 /chapter13
parent702b696cc74a20cf84172ee2ce59ace4c980ee75 (diff)
downloadSimple-49af186140611daa9c840189139b59c854f1889c.tar.gz
Simple-49af186140611daa9c840189139b59c854f1889c.zip
Fix chapter12 grammar
Diffstat (limited to 'chapter13')
-rw-r--r--chapter13/docs/12-grammar.md129
1 files changed, 0 insertions, 129 deletions
diff --git a/chapter13/docs/12-grammar.md b/chapter13/docs/12-grammar.md
deleted file mode 100644
index 9370024e..00000000
--- a/chapter13/docs/12-grammar.md
+++ /dev/null
@@ -1,129 +0,0 @@
-# Grammar for Chapter 11
-
-```antlrv4
-grammar SimpleLanguage;
-
-program
- : statement+ EOF
- ;
-
-statement
- : returnStatement
- | structDeclaration
- | declStatement
- | blockStatment
- | expressionStatement
- | ifStatement
- | whileStatement
- | breakStatement
- | continueStatment
- | metaStatement
- ;
-
-field
- : 'int' IDENTIFIER ';'
- ;
-
-fields
- : field+
- ;
-
-structDeclaration
- : 'struct' IDENTIFIER '{' fields '}'
- ;
-
-whileStatement
- : 'while' '(' expression ')' statement
- ;
-
-breakStatement
- : 'break' ';'
- ;
-
-continueStatement
- : 'continue' ';'
- ;
-
-ifStatement
- : 'if' '(' expression ')' statement ('else' statement)?
- ;
-
-metaStatement
- : '#showGraph' ';'
- ;
-
-expressionStatement
- : IDENTIFIER '=' expression ';'
- | fieldExpression '=' expression ';'
- ;
-
-blockStatement
- : '{' statement+ '}'
- ;
-
-structName
- : IDENTIFIER
- ;
-
-declStatement
- : 'int' IDENTIFIER '=' expression ';'
- | structName IDENTIFIER ('?')? '=' expression ';'
- ;
-
-returnStatement
- : 'return' expression ';'
- ;
-
-expression
- : comparisonExpression
- ;
-
-comparisonExpression
- : additiveExpression (('==' | '!='| '>'| '<'| '>='| '<=') additiveExpression)*
- ;
-
-additiveExpression
- : multiplicativeExpression (('+' | '-') multiplicativeExpression)*
- ;
-
-multiplicativeExpression
- : unaryExpression (('*' | '/') unaryExpression)*
- ;
-
-unaryExpression
- : ('-') unaryExpression
- | '!' unaryExpression
- | primaryExpression
- ;
-
-newExpression
- : 'new' IDENTIFIER
- ;
-
-fieldExpression
- : primaryExpresson '.' IDENTIFIER
- ;
-
-primaryExpression
- : IDENTIFIER
- | INTEGER_LITERAL
- | 'true'
- | 'false'
- | 'null'
- | newExpression
- | '(' expression ')'
- | fieldExpression
- ;
-
-INTEGER_LITERAL
- : [1-9][0-9]*
- | [0]
- ;
-
-IDENTIFIER
- : NON_DIGIT (NON_DIGIT | DIGIT)*
- ;
-
-NON_DIGIT: [a-zA-Z_];
-DEC_DIGIT: [0-9];
-```