From 0253cd7b3609f2d832c78e933521eaf63f7156cd Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Tue, 13 Oct 2020 18:07:22 -0600 Subject: some syntax work --- syntax.md | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 7 deletions(-) (limited to 'syntax.md') diff --git a/syntax.md b/syntax.md index c0b043f..550fbcc 100644 --- a/syntax.md +++ b/syntax.md @@ -36,6 +36,7 @@ A *keyword* is one of the following literal words: - `extern` - `float` - `for` +- `function` - `if` - `include` - `int` @@ -161,10 +162,76 @@ A *block comment* begins with the characters `/*` if they occur outside of a str The syntax of Crowbar is given as a [parsing expression grammar](https://en.wikipedia.org/wiki/Parsing_expression_grammar): -| Syntax Element | | Parsing Expression | -|:-----------------|:-:|:-------------------------| -|ImplementationFile| ← |ImplementationFileElement*| -|HeaderFile | ← |HeaderFileElement* | -|HeaderFileElement | ← |IncludeStatement | -| | / |TypeDeclaration | -| | / |FunctionDeclaration | +## Entry points + +``` +HeaderFile ← HeaderFileElement+ +HeaderFileElement ← IncludeStatement / + TypeDeclaration / + FunctionDeclaration + +ImplementationFile ← ImplementationFileElement+ +ImplementationFileElement ← HeaderFileElement / + FunctionDefinition +``` + +## Top-level elements + +``` +IncludeStatement ← 'include' string-literal ';' + +TypeDeclaration ← StructDeclaration / + EnumDeclaration +StructDeclaration ← 'struct' identifier '{' VariableDeclaration+ '}' ';' +EnumDeclaration ← 'enum' identifier '{' EnumItem+ '}' ';' +EnumItem ← identifier ',' + +FunctionDeclaration ← FunctionSignature ';' +FunctionDefinition ← FunctionSignature Block +FunctionSignature ← Type identifier '(' Argument* ')' +Argument ← Type identifier ',' +``` + +## Statements + +``` +Statement ← + +Block ← '{' Statement* '}' + +VariableDeclaration ← Type identifier ';' +``` + +## Types + +``` +Type ← BasicType / + 'const' BasicType / + BasicType '*' / + BasicType '[' Expression ']' / + Type 'function' '(' (BasicType ',')* ')' +BasicType ← 'void' / + IntegerType / + 'signed' IntegerType / + 'unsigned' IntegerType / + 'float' / + 'double' / + 'bool' / + 'struct' identifier / + 'enum' identifier / + identifier / + '(' Type ')' +IntegerType ← 'char' / + 'short' / + 'int' / + 'long' +``` + +## Expressions + +``` +AssignmentTargetExpression ← +Expression ← +``` + +[![Creative Commons BY-SA License](https://i.creativecommons.org/l/by-sa/4.0/80x15.png)](http://creativecommons.org/licenses/by-sa/4.0/) -- cgit v1.2.3