aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--syntax.md70
1 files changed, 65 insertions, 5 deletions
diff --git a/syntax.md b/syntax.md
index 0e4e7ab..79b92ad 100644
--- a/syntax.md
+++ b/syntax.md
@@ -6,7 +6,7 @@ A Crowbar source file is UTF-8.
Crowbar source files can come in two varieties, an *implementation file* and a *header file*.
An implementation file conventionally has a `.cro` extension, and a header file conventionally has a `.hro` extension.
-A Crowbar source file is read into memory in two phases: *scanning* (which converts text into an unstructured sequence of tokens) and *parsing* (which converts an unstructured sequence of tokens into an Abstract Syntax Tree, or AST).
+A Crowbar source file is read into memory in two phases: *scanning* (which converts text into an unstructured sequence of tokens) and *parsing* (which converts an unstructured sequence of tokens into a parse tree).
# Scanning
@@ -192,8 +192,8 @@ TypedefDeclaration ← 'typedef' identifier '=' Type ';'
FunctionDeclaration ← FunctionSignature ';'
FunctionDefinition ← FunctionSignature Block
-FunctionSignature ← Type identifier '(' Arguments ')'
-Arguments ← Type identifier ',' Arguments /
+FunctionSignature ← Type identifier '(' SignatureArguments ')'
+SignatureArguments ← Type identifier ',' SignatureArguments /
Type identifier ','?
```
@@ -279,8 +279,68 @@ IntegerType ← 'char' /
## Expressions
```
-AssignmentTargetExpression ←
-Expression ←
+AssignmentTargetExpression ← identifier ATEElementSuffix*
+ATEElementSuffix ← '[' Expression ']' /
+ '.' identifier /
+ '->' identifier
+
+AtomicExpression ← identifier /
+ constant /
+ string-literal /
+ '(' Expression ')'
+
+ObjectExpression ← AtomicExpression ObjectSuffix* /
+ ArrayLiteralExpression /
+ StructLiteralExpression
+ObjectSuffix ← '[' Expression ']' /
+ '(' CommasExpressionList? ')' /
+ '.' identifier /
+ '->' identifier
+CommasExpressionList ← Expression ',' CommasExpressionList? /
+ Expression ','?
+ArrayLiteralExpression ← '{' CommasExpressionList '}'
+StructLiteralExpression ← '{' StructLiteralBody '}'
+StructLiteralBody ← StructLiteralElement ',' StructLiteralBody? /
+ StructLiteralElement ','?
+StructLiteralElement ← '.' identifier '=' Expression
+
+FactorExpression ← '(' Type ')' FactorExpression /
+ '&' FactorExpression /
+ '*' FactorExpression /
+ '+' FactorExpression /
+ '-' FactorExpression /
+ '~' FactorExpression /
+ '!' FactorExpression /
+ 'sizeof' FactorExpression /
+ 'sizeof' Type /
+ ObjectExpression
+
+TermExpression ← FactorExpression TermSuffix*
+TermSuffix ← '*' FactorExpression /
+ '/' FactorExpression /
+ '%' FactorExpression
+
+ArithmeticExpression ← TermExpression ArithmeticSuffix*
+ArithmeticSuffix ← '+' TermExpression /
+ '-' TermExpression
+
+BitwiseOpExpression ← ArithmeticExpression '<<' ArithmeticExpression /
+ ArithmeticExpression '>>' ArithmeticExpression /
+ ArithmeticExpression '&' ArithmeticExpression /
+ ArithmeticExpression '^' ArithmeticExpression /
+ ArithmeticExpression '|' ArithmeticExpression /
+ ArithmeticExpression
+
+ComparisonExpression ← BitwiseOpExpression '==' BitwiseOpExpression /
+ BitwiseOpExpression '!=' BitwiseOpExpression /
+ BitwiseOpExpression '<=' BitwiseOpExpression /
+ BitwiseOpExpression '>=' BitwiseOpExpression /
+ BitwiseOpExpression '<' BitwiseOpExpression /
+ BitwiseOpExpression '>' BitwiseOpExpression /
+ BitwiseOpExpression
+
+Expression ← ComparisonExpression ('&&' ComparisonExpression)* /
+ ComparisonExpression ('||' ComparisonExpression)*
```
[![Creative Commons BY-SA License](https://i.creativecommons.org/l/by-sa/4.0/80x15.png)](http://creativecommons.org/licenses/by-sa/4.0/)