From 1a79ddba451159eaf1e5bc6964b68406a16bf224 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Mon, 18 Mar 2019 16:06:55 -0400 Subject: [PATCH 1/6] Add definition of full expression --- spec/expression.dd | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/expression.dd b/spec/expression.dd index 7a3ff61835..524597a49b 100644 --- a/spec/expression.dd +++ b/spec/expression.dd @@ -4,11 +4,24 @@ $(SPEC_S Expressions, $(HEADERNAV_TOC) +$(P This chapter defines the syntax, order of evaluation, and semantics of expressions. An expression is a sequence of operators and operands that specifies an evaluation.) + $(P Expressions are used to compute values with a resulting type. These values can then be assigned, tested, or ignored. Expressions can also have side effects. ) +$(H2 $(LNAME2 general, Definitions and Terms)) + +$(DDOC_ANCHOR define-full-expression)$(P $(B Definition) ($(DOUBLEQUOTE Full expression)): For any expression $(I expr) in a D program, we define the full expression of $(I expr) as follows. If $(I expr) parses as a subexpression of another expression $(I expr$(SUBSCRIPT 1)), then the full expression of $(I expr) is the full expression of $(I expr$(SUBSCRIPT 1)). Otherwise, $(I expr) is its own full expression.) + +$(P Each expression has a unique full expression.) + +Example: in the statement `return f() + g() * 2;`, the full expression of `g() * 2` is `f() + g() * 2`, but not the full expression of `f() + g()` because the latter is not parsed as a subexpression. + +Note: Although the definition is straightforward, a few subtleties exist related to function literals. In the statement `return (() => x + f())() * g();`, the full expression of `f()` is `x + f()`, not the expression passed to `return`. This is because the parent of `x + f()` has function literal type, not expression type. + + $(H2 $(LNAME2 order-of-evaluation, Order Of Evaluation)) $(P Binary expressions are evaluated in strictly left-to-right order. From 2d22f51f9cc0904fa4e0800865ae8fb340c15f19 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Mon, 18 Mar 2019 16:12:16 -0400 Subject: [PATCH 2/6] Insert newlines sigh --- spec/expression.dd | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/spec/expression.dd b/spec/expression.dd index 524597a49b..3703e9b8bb 100644 --- a/spec/expression.dd +++ b/spec/expression.dd @@ -4,7 +4,8 @@ $(SPEC_S Expressions, $(HEADERNAV_TOC) -$(P This chapter defines the syntax, order of evaluation, and semantics of expressions. An expression is a sequence of operators and operands that specifies an evaluation.) +$(P This chapter defines the syntax, order of evaluation, and semantics of expressions. An expression is a sequence +of operators and operands that specifies an evaluation.) $(P Expressions are used to compute values with a resulting type. These values can then be assigned, @@ -13,13 +14,19 @@ $(P This chapter defines the syntax, order of evaluation, and semantics of expre $(H2 $(LNAME2 general, Definitions and Terms)) -$(DDOC_ANCHOR define-full-expression)$(P $(B Definition) ($(DOUBLEQUOTE Full expression)): For any expression $(I expr) in a D program, we define the full expression of $(I expr) as follows. If $(I expr) parses as a subexpression of another expression $(I expr$(SUBSCRIPT 1)), then the full expression of $(I expr) is the full expression of $(I expr$(SUBSCRIPT 1)). Otherwise, $(I expr) is its own full expression.) +$(DDOC_ANCHOR define-full-expression)$(P $(B Definition) ($(DOUBLEQUOTE Full expression)): For any expression $(I expr) +in a D program, we define the full expression of $(I expr) as follows. If $(I expr) parses as a subexpression of another +expression $(I expr$(SUBSCRIPT 1)), then the full expression of $(I expr) is the full expression +of $(I expr$(SUBSCRIPT 1)). Otherwise, $(I expr) is its own full expression.) $(P Each expression has a unique full expression.) -Example: in the statement `return f() + g() * 2;`, the full expression of `g() * 2` is `f() + g() * 2`, but not the full expression of `f() + g()` because the latter is not parsed as a subexpression. +Example: in the statement `return f() + g() * 2;`, the full expression of `g() * 2` is `f() + g() * 2`, but not the +full expression of `f() + g()` because the latter is not parsed as a subexpression. -Note: Although the definition is straightforward, a few subtleties exist related to function literals. In the statement `return (() => x + f())() * g();`, the full expression of `f()` is `x + f()`, not the expression passed to `return`. This is because the parent of `x + f()` has function literal type, not expression type. +Note: Although the definition is straightforward, a few subtleties exist related to function literals. In the +statement `return (() => x + f())() * g();`, the full expression of `f()` is `x + f()`, not the expression passed +to `return`. This is because the parent of `x + f()` has function literal type, not expression type. $(H2 $(LNAME2 order-of-evaluation, Order Of Evaluation)) From 300c5ba555c992e93ef9813e5f2800e3ea8f2cfc Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Mon, 18 Mar 2019 16:13:07 -0400 Subject: [PATCH 3/6] Moar wraparoo --- spec/expression.dd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/expression.dd b/spec/expression.dd index 3703e9b8bb..efe38238b5 100644 --- a/spec/expression.dd +++ b/spec/expression.dd @@ -14,10 +14,10 @@ of operators and operands that specifies an evaluation.) $(H2 $(LNAME2 general, Definitions and Terms)) -$(DDOC_ANCHOR define-full-expression)$(P $(B Definition) ($(DOUBLEQUOTE Full expression)): For any expression $(I expr) -in a D program, we define the full expression of $(I expr) as follows. If $(I expr) parses as a subexpression of another -expression $(I expr$(SUBSCRIPT 1)), then the full expression of $(I expr) is the full expression -of $(I expr$(SUBSCRIPT 1)). Otherwise, $(I expr) is its own full expression.) +$(DDOC_ANCHOR define-full-expression)$(P $(B Definition) ($(DOUBLEQUOTE Full expression)): For any expression +$(I expr) in a D program, we define the full expression of $(I expr) as follows. If $(I expr) parses as a +subexpression of another expression $(I expr$(SUBSCRIPT 1)), then the full expression of $(I expr) is the +full expression of $(I expr$(SUBSCRIPT 1)). Otherwise, $(I expr) is its own full expression.) $(P Each expression has a unique full expression.) From 9537cf77485f4ea439c39b28535244235bc0e508 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Mon, 18 Mar 2019 16:13:42 -0400 Subject: [PATCH 4/6] Better anchor name --- spec/expression.dd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/expression.dd b/spec/expression.dd index efe38238b5..b453097d3d 100644 --- a/spec/expression.dd +++ b/spec/expression.dd @@ -12,7 +12,7 @@ of operators and operands that specifies an evaluation.) tested, or ignored. Expressions can also have side effects. ) -$(H2 $(LNAME2 general, Definitions and Terms)) +$(H2 $(LNAME2 definitions-and-terms, Definitions and Terms)) $(DDOC_ANCHOR define-full-expression)$(P $(B Definition) ($(DOUBLEQUOTE Full expression)): For any expression $(I expr) in a D program, we define the full expression of $(I expr) as follows. If $(I expr) parses as a From b435eade3ae96f349e71710e47a353608fff6a8b Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Mon, 18 Mar 2019 19:40:14 -0400 Subject: [PATCH 5/6] feedback --- spec/expression.dd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/expression.dd b/spec/expression.dd index b453097d3d..3089755db1 100644 --- a/spec/expression.dd +++ b/spec/expression.dd @@ -4,8 +4,8 @@ $(SPEC_S Expressions, $(HEADERNAV_TOC) -$(P This chapter defines the syntax, order of evaluation, and semantics of expressions. An expression is a sequence -of operators and operands that specifies an evaluation.) +$(P An expression is a sequence of operators and operands that specifies an evaluation. +The syntax, order of evaluation, and semantics of expressions are as follows.) $(P Expressions are used to compute values with a resulting type. These values can then be assigned, @@ -15,7 +15,7 @@ of operators and operands that specifies an evaluation.) $(H2 $(LNAME2 definitions-and-terms, Definitions and Terms)) $(DDOC_ANCHOR define-full-expression)$(P $(B Definition) ($(DOUBLEQUOTE Full expression)): For any expression -$(I expr) in a D program, we define the full expression of $(I expr) as follows. If $(I expr) parses as a +$(I expr), the full expression of $(I expr) is defined as follows. If $(I expr) parses as a subexpression of another expression $(I expr$(SUBSCRIPT 1)), then the full expression of $(I expr) is the full expression of $(I expr$(SUBSCRIPT 1)). Otherwise, $(I expr) is its own full expression.) From 4ca4668427f3c0968dd96eac3aa6ea80bc0df99c Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Mon, 18 Mar 2019 21:27:20 -0400 Subject: [PATCH 6/6] whitespace --- spec/expression.dd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/expression.dd b/spec/expression.dd index 3089755db1..37292dd7bc 100644 --- a/spec/expression.dd +++ b/spec/expression.dd @@ -24,7 +24,7 @@ $(P Each expression has a unique full expression.) Example: in the statement `return f() + g() * 2;`, the full expression of `g() * 2` is `f() + g() * 2`, but not the full expression of `f() + g()` because the latter is not parsed as a subexpression. -Note: Although the definition is straightforward, a few subtleties exist related to function literals. In the +Note: Although the definition is straightforward, a few subtleties exist related to function literals. In the statement `return (() => x + f())() * g();`, the full expression of `f()` is `x + f()`, not the expression passed to `return`. This is because the parent of `x + f()` has function literal type, not expression type.