diff options
-rw-r--r-- | syntax.md | 71 |
1 files changed, 60 insertions, 11 deletions
@@ -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' / |