aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2020-10-13 18:07:22 -0600
committerMelody Horn <melody@boringcactus.com>2020-10-13 18:07:22 -0600
commit0253cd7b3609f2d832c78e933521eaf63f7156cd (patch)
tree39954ee223a64dec7215108e9711b5122937215d
parente57941f5f43507c275623bc82d4f5f93103876ca (diff)
downloadspec-0253cd7b3609f2d832c78e933521eaf63f7156cd.tar.gz
spec-0253cd7b3609f2d832c78e933521eaf63f7156cd.zip
some syntax work
-rw-r--r--syntax.md81
1 files changed, 74 insertions, 7 deletions
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/)