From ccaec9990c21748e5fe52c9eb39f8f82b507f8db Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Wed, 14 Oct 2020 10:50:11 -0600 Subject: finish out statements --- syntax.md | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 11 deletions(-) (limited to 'syntax.md') 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' / -- cgit v1.2.3