aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2020-10-14 11:43:21 -0600
committerMelody Horn <melody@boringcactus.com>2020-10-14 11:43:21 -0600
commit9e7bc38302bfbb0469073ba8ed77e1cc4c713956 (patch)
tree22fbd08013ff8045b1202f55db80afa13cfd5264
parentccaec9990c21748e5fe52c9eb39f8f82b507f8db (diff)
downloadspec-9e7bc38302bfbb0469073ba8ed77e1cc4c713956.tar.gz
spec-9e7bc38302bfbb0469073ba8ed77e1cc4c713956.zip
finish expressions, maybe
-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/)