aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2020-11-03 23:21:52 -0700
committerMelody Horn <melody@boringcactus.com>2020-11-03 23:21:52 -0700
commit1377c4f20de27bf9fd088450bb05ab092c149fe1 (patch)
treeab0389638df85a5b5a95b5f52c399684592ea2cd
parentcc2408e68a23414cf1af351aa43e7c1d50980445 (diff)
downloadspec-1377c4f20de27bf9fd088450bb05ab092c149fe1.tar.gz
spec-1377c4f20de27bf9fd088450bb05ab092c149fe1.zip
stub out expression syntax
-rw-r--r--index.rst1
-rw-r--r--language/expression.rst81
-rw-r--r--language/index.rst1
-rw-r--r--syntax.md75
4 files changed, 82 insertions, 76 deletions
diff --git a/index.rst b/index.rst
index cab4271..e08d3a6 100644
--- a/index.rst
+++ b/index.rst
@@ -54,7 +54,6 @@ Chapters
vs-c
safety
errors
- syntax
language/index
LICENSE
todo
diff --git a/language/expression.rst b/language/expression.rst
new file mode 100644
index 0000000..60c81c7
--- /dev/null
+++ b/language/expression.rst
@@ -0,0 +1,81 @@
+Expressions
+-----------
+
+.. crowbar:element:: AtomicExpression <- identifier / constant / string-literal / '(' Expression ')'
+
+.. crowbar:element:: ObjectExpression <- AtomicExpression ObjectSuffix* / ArrayLiteral / StructLiteral
+ ObjectSuffix <- ArrayIndexSuffix / FunctionCallSuffix / StructElementSuffix / StructPointerElementSuffix
+
+.. crowbar:element:: ArrayIndexSuffix <- '[' Expression ']'
+
+.. crowbar:element:: FunctionCallSuffix <- '(' CommasExpressionList? ')'
+ CommasExpressionList <- Expression (',' Expression)* ','?
+
+.. crowbar:element:: StructElementSuffix <- '.' identifier
+
+.. crowbar:element:: StructPointerElementSuffix <- '->' identifier
+
+.. crowbar:element:: ArrayLiteral <- '{' CommasExpressionList '}'
+
+.. crowbar:element:: StructLiteral <- '{' StructLiteralElement (',' StructLiteralElement)* ','? '}'
+ StructLiteralElement <- '.' identifier '=' Expression
+
+.. crowbar:element:: FactorExpression <- CastExpression / AddressOfExpression / DerefExpression / PositiveExpression / NegativeExpression / BitwiseNotExpression / LogicalNotExpression / SizeofExpression / ObjectExpression
+
+.. crowbar:element:: CastExpression <- '(' Type ')' ObjectExpression
+
+.. crowbar:element:: AddressOfExpression <- '&' ObjectExpression
+
+.. crowbar:element:: DerefExpression <- '*' ObjectExpression
+
+.. crowbar:element:: PositiveExpression <- '+' ObjectExpression
+
+.. crowbar:element:: NegativeExpression <- '-' ObjectExpression
+
+.. crowbar:element:: BitwiseNotExpression <- '~' ObjectExpression
+
+.. crowbar:element:: LogicalNotExpression <- '!' ObjectExpression
+
+.. crowbar:element:: SizeofExpression <- 'sizeof' ObjectExpression / 'sizeof' Type
+
+.. crowbar:element:: TermExpression <- FactorExpression TermSuffix?
+ TermSuffix <- ('*' FactorExpression)+ / ('/' FactorExpression)+ / ('%' FactorExpression)+
+
+.. crowbar:element:: ArithmeticExpression <- TermExpression ArithmeticSuffix?
+ ArithmeticSuffix <- ('+' TermExpression)+ / ('-' TermExpression)+
+
+.. crowbar:element:: BitwiseOpExpression <- ShiftExpression / XorExpression / BitwiseAndExpression / BitwiseOrExpression / ArithmeticExpression
+
+.. crowbar:element:: ShiftExpression <- ArithmeticExpression '<<' ArithmeticExpression / ArithmeticExpression '>>' ArithmeticExpression
+
+.. crowbar:element:: XorExpression <- ArithmeticExpression '^' ArithmeticExpression
+
+.. crowbar:element:: BitwiseAndExpression <- ArithmeticExpression ('&' ArithmeticExpression)+
+
+.. crowbar:element:: BitwiseOrExpression <- ArithmeticExpression ('|' ArithmeticExpression)+
+
+.. crowbar:element:: ComparisonExpression <- EqualExpression / NotEqualExpression / LessEqExpression / GreaterEqExpression / LessThanExpression / GreaterThanExpression / BitwiseOpExpression
+
+.. crowbar:element:: EqualExpression <- BitwiseOpExpression '==' BitwiseOpExpression
+
+.. crowbar:element:: NotEqualExpression <- BitwiseOpExpression '!=' BitwiseOpExpression
+
+.. crowbar:element:: LessEqExpression <- BitwiseOpExpression '<=' BitwiseOpExpression
+
+.. crowbar:element:: GreaterEqExpression <- BitwiseOpExpression '>=' BitwiseOpExpression
+
+.. crowbar:element:: LessThanExpression <- BitwiseOpExpression '<' BitwiseOpExpression
+
+.. crowbar:element:: GreaterThanExpression <- BitwiseOpExpression '>' BitwiseOpExpression
+
+.. crowbar:element:: LogicalOpExpression <- LogicalAndExpression / LogicalOrExpression / ComparisonExpression
+
+.. crowbar:element:: LogicalAndExpression <- ComparisonExpression ('&&' ComparisonExpression)+
+
+.. crowbar:element:: LogicalOrExpression <- ComparisonExpression ('||' ComparisonExpression)+
+
+.. crowbar:element:: Expression <- LogicalOpExpression
+
+.. todo:: literally all the expression definitions
+
+.. todo:: figure out if this hierarchy can be tidied up
diff --git a/language/index.rst b/language/index.rst
index 3f776f9..7d11d4f 100644
--- a/language/index.rst
+++ b/language/index.rst
@@ -21,3 +21,4 @@ Syntax elements in this document are given in the form of `parsing expression gr
functions
statements/index
types
+ expression
diff --git a/syntax.md b/syntax.md
deleted file mode 100644
index 083103c..0000000
--- a/syntax.md
+++ /dev/null
@@ -1,75 +0,0 @@
-# Syntax (old)
-
-### Statements
-
-```PEG
-ExpressionStatement ← Expression ';'
-```
-
-### Expressions
-
-```PEG
-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)+ /
- ComparisonExpression
-```