aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2020-10-14 10:50:11 -0600
committerMelody Horn <melody@boringcactus.com>2020-10-14 10:50:11 -0600
commitccaec9990c21748e5fe52c9eb39f8f82b507f8db (patch)
treee946b16db6b02dea3063c1682d133337137cc72c
parent21a92263f5e958f7b95c751d6334626b35ed1a19 (diff)
downloadspec-ccaec9990c21748e5fe52c9eb39f8f82b507f8db.tar.gz
spec-ccaec9990c21748e5fe52c9eb39f8f82b507f8db.zip
finish out statements
-rw-r--r--syntax.md71
1 files changed, 60 insertions, 11 deletions
diff --git a/syntax.md b/syntax.md
index 269a16d..0e4e7ab 100644
--- a/syntax.md
+++ b/syntax.md
@@ -47,6 +47,7 @@ A *keyword* is one of the following literal words:
- `sizeof`
- `struct`
- `switch`
+- `typedef`
- `unsigned`
- `void`
- `while`
@@ -181,25 +182,73 @@ ImplementationFileElement ← HeaderFileElement /
IncludeStatement ← 'include' string-literal ';'
TypeDeclaration ← StructDeclaration /
- EnumDeclaration
+ EnumDeclaration /
+ TypedefDeclaration
StructDeclaration ← 'struct' identifier '{' VariableDeclaration+ '}' ';'
-EnumDeclaration ← 'enum' identifier '{' EnumItem+ '}' ';'
-EnumItem ← identifier ','
+EnumDeclaration ← 'enum' identifier '{' EnumBody '}' ';'
+EnumBody ← identifier ',' EnumBody /
+ identifier ','?
+TypedefDeclaration ← 'typedef' identifier '=' Type ';'
FunctionDeclaration ← FunctionSignature ';'
FunctionDefinition ← FunctionSignature Block
-FunctionSignature ← Type identifier '(' Argument* ')'
-Argument ← Type identifier ','
+FunctionSignature ← Type identifier '(' Arguments ')'
+Arguments ← Type identifier ',' Arguments /
+ Type identifier ','?
```
## Statements
```
-Statement ←
-
-Block ← '{' Statement* '}'
-
-VariableDeclaration ← Type identifier ';'
+Block ← '{' Statement* '}'
+
+Statement ← VariableDefinition /
+ VariableDeclaration /
+ IfStatement /
+ SwitchStatement /
+ WhileStatement /
+ DoWhileStatement /
+ ForStatement /
+ FlowControlStatement /
+ AssignmentStatement /
+ ExpressionStatement
+
+VariableDefinition ← Type identifier '=' Expression ';'
+VariableDeclaration ← Type identifier ';'
+
+IfStatement ← 'if' Expression Block 'else' Block /
+ 'if' Expression Block
+
+SwitchStatement ← 'switch' Expression '{' SwitchCase+ '}'
+SwitchCase ← CaseSpecifier Block /
+ 'default' Block
+CaseSpecifier ← 'case' Expression ',' CaseSpecifier /
+ 'case' Expression ','?
+
+WhileStatement ← 'while' Expression Block
+DoWhileStatement ← 'do' Block 'while' Expression ';'
+ForStatement ← 'for' VariableDefinition? ';' Expression ';' AssignmentStatementBody? Block
+
+FlowControlStatement ← 'continue' ';' /
+ 'break' ';' /
+ 'return' Expression? ';'
+
+AssignmentStatement ← AssignmentStatementBody ';'
+AssignmentStatementBody ← AssignmentTargetExpression '=' Expression /
+ AssignmentTargetExpression '+=' Expression /
+ AssignmentTargetExpression '-=' Expression /
+ AssignmentTargetExpression '*=' Expression /
+ AssignmentTargetExpression '/=' Expression /
+ AssignmentTargetExpression '%=' Expression /
+ AssignmentTargetExpression '<<=' Expression /
+ AssignmentTargetExpression '>>=' Expression /
+ AssignmentTargetExpression '&=' Expression /
+ AssignmentTargetExpression '^=' Expression /
+ AssignmentTargetExpression '|=' Expression /
+ AssignmentTargetExpression '++' /
+ AssignmentTargetExpression '--'
+
+ExpressionStatement ← Expression ';'
```
## Types
@@ -219,7 +268,7 @@ BasicType ← 'void' /
'bool' /
'struct' identifier /
'enum' identifier /
- identifier /
+ 'typedef' identifier /
'(' Type ')'
IntegerType ← 'char' /
'short' /