* [PATCH 0/4] docs: spec: constant initialization and assignments
@ 2024-04-16 20:17 ricardo_kagawa
2024-04-16 20:17 ` [PATCH 1/4] docs: spec: refactor grammar specification ricardo_kagawa
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: ricardo_kagawa @ 2024-04-16 20:17 UTC (permalink / raw)
To: ~johnnyrichard/olang-devel; +Cc: Ricardo Kagawa
From: Ricardo Kagawa <ricardo_kagawa@disroot.org>
For this patchset I'm assuming that:
- We agreed constants should be initialized immediately, and that this
should be validated in syntax, rather than during semantic analysis;
- We agreed that chained assignments and related constructs were indeed
not desired, and can be safely removed.
The last commit in the set is optional, and should be removed or
reverted depending on when the definitions of binary operators land. You
may choose to not include it regardless, but I'm not a great fan of
specifications that are not self-consistent.
-- >8 --
This patchset includes changes suggested in a superseded patchset:
- Refactoring and renaming non-terminals in the grammar specification
for better clarity in definitions related to variable declarations
and assignments;
- Removing the ability to declare uninitialized constant variables;
- Removing the ability to use assignments as expressions;
- This also removes the ability to use chained assignments; and
- This also removes the ability to use assignments inside
conditional clauses of future statements.
- Temporarily removes assignment operators that still don't have their
corresponding binary operators defined. Please remove or revert this
last commit if those missing definitions are incorporated before this
patchset. Otherwise, revert it after they are applied.
Ricardo Kagawa (4):
docs: spec: refactor grammar specification
docs: spec: immediate constant initialization
docs: spec: remove assignment as expression
docs: spec: postpone assignment operators
docs/pages/language-specification.md | 36 +++++++++++-----------------
1 file changed, 14 insertions(+), 22 deletions(-)
--
2.44.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/4] docs: spec: refactor grammar specification
2024-04-16 20:17 [PATCH 0/4] docs: spec: constant initialization and assignments ricardo_kagawa
@ 2024-04-16 20:17 ` ricardo_kagawa
2024-04-16 22:32 ` Johnny Richard
2024-04-16 20:17 ` [PATCH 2/4] docs: spec: immediate constant initialization ricardo_kagawa
` (3 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: ricardo_kagawa @ 2024-04-16 20:17 UTC (permalink / raw)
To: ~johnnyrichard/olang-devel; +Cc: Ricardo Kagawa
From: Ricardo Kagawa <ricardo_kagawa@disroot.org>
- Moved statements common to the translation unit and function bodies to
their own non-terminal.
- Moved some non-terminals from the "Statements" section to the
"Functions" section, as there will be some statements that are
function-body specific, some that are translation-unit specific, and
some that are common to both.
- Renamed "assign" to "assignment", for better wording.
- Renamed <integer> to <integer-literal> to make it more explicit that
this symbol represents a literal value.
- Replaced <identifier> in <expression> for <variable-name> to make it
more explicit that it must refer to a variable, and not just any
identifier.
Signed-off-by: Ricardo Kagawa <ricardo_kagawa@disroot.org>
---
docs/pages/language-specification.md | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/docs/pages/language-specification.md b/docs/pages/language-specification.md
index 4d0eb36..9f4383d 100644
--- a/docs/pages/language-specification.md
+++ b/docs/pages/language-specification.md
@@ -24,10 +24,11 @@ language.
(* Entry Point *)
<translation-unit> ::= (<ows> <external-declaration> <ows> (<end-of-statement> | <end-of-file>))*
-<external-declaration> ::= <function-definition> | <variable-definition>
+(* Translation Unit *)
+<external-declaration> ::= <common-statement> | <function-definition>
(* Variables *)
-<variable-definition> ::= <variable-qualifier> <ws> <variable-name> <ows> ':' <ows> <type> (<ows> <assign-operator> <ows> <expression>)?
+<variable-definition> ::= <variable-qualifier> <ws> <variable-name> <ows> ':' <ows> <type> (<ows> <assignment-operator> <ows> <expression>)?
<variable-qualifier> ::= 'var'
| 'const'
<variable-name> ::= <identifier>
@@ -38,17 +39,18 @@ language.
<function-parameters> ::= '(' <ows> ')'
<return-type> ::= <type>
<function-body> ::= <block>
+<block> ::= '{' <ows> <statement> <ows> (<end-of-statement> <ows> <statement> <ows>)* <end-of-statement>? <ows> '}'
+<statement> ::= <common-statement> | <return-statement>
+<return-statement> ::= 'return' <ws> <expression>
(* Statements *)
-<block> ::= '{' <ows> <statement> <ows> (<end-of-statement> <ows> <statement> <ows>)* <end-of-statement>? <ows> '}'
<end-of-statement> ::= ';' | <line-break>
-<statement> ::= <return-statement> | <variable-definition> | <assign-expression>
-<return-statement> ::= 'return' <ws> <expression>
+<common-statement> ::= <variable-definition> | <assignment-expression>
(* Expressions *)
-<expression> ::= <integer> | <identifier>
-<assign-expression> ::= <variable-name> <ows> <assign-operator> <ows> <expression>
-<assign-operator> ::= '='
+<expression> ::= <integer-literal> | <variable-name>
+<assignment-expression> ::= <variable-name> <ows> <assignment-operator> <ows> <expression>
+<assignment-operator> ::= '='
| '*='
| '/='
| '%='
@@ -65,7 +67,7 @@ language.
<identifier> ::= (<alpha> | '_') (<alpha> | <digit> | '_')*
(* Literals *)
-<integer> ::= <integer-base10> | <integer-base16>
+<integer-literal> ::= <integer-base10> | <integer-base16>
<integer-base10> ::= #'[1-9]' (<digit> | '_')* | '0'
<integer-base16> ::= #'0[Xx]' <hex-digit> (<hex-digit> | '_')*
--
2.44.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/4] docs: spec: immediate constant initialization
2024-04-16 20:17 [PATCH 0/4] docs: spec: constant initialization and assignments ricardo_kagawa
2024-04-16 20:17 ` [PATCH 1/4] docs: spec: refactor grammar specification ricardo_kagawa
@ 2024-04-16 20:17 ` ricardo_kagawa
2024-04-16 22:33 ` Johnny Richard
2024-04-16 20:17 ` [PATCH 3/4] docs: spec: remove assignment as expression ricardo_kagawa
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: ricardo_kagawa @ 2024-04-16 20:17 UTC (permalink / raw)
To: ~johnnyrichard/olang-devel; +Cc: Ricardo Kagawa
From: Ricardo Kagawa <ricardo_kagawa@disroot.org>
This commit prevents declarations of uninitialized constants, as well as
prevents the use of assignment operators in variable and constant
declarations. This change was originally suggested by Maniero, with
different non-terminal names.
Signed-off-by: Ricardo Kagawa <ricardo_kagawa@disroot.org>
---
docs/pages/language-specification.md | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/docs/pages/language-specification.md b/docs/pages/language-specification.md
index 9f4383d..8d8544a 100644
--- a/docs/pages/language-specification.md
+++ b/docs/pages/language-specification.md
@@ -28,10 +28,10 @@ language.
<external-declaration> ::= <common-statement> | <function-definition>
(* Variables *)
-<variable-definition> ::= <variable-qualifier> <ws> <variable-name> <ows> ':' <ows> <type> (<ows> <assignment-operator> <ows> <expression>)?
-<variable-qualifier> ::= 'var'
- | 'const'
-<variable-name> ::= <identifier>
+<variable-definition> ::= 'var' <ws> <variable-name> <ows> ':' <ows> <type> <ows> <variable-initializer>?
+<constant-definition> ::= 'const' <ws> <variable-name> <ows> ':' <ows> <type> <ows> <variable-initializer>
+<variable-name> ::= <identifier>
+<variable-initializer> ::= '=' <ows> <expression>
(* Functions *)
<function-definition> ::= 'fn' <ws> <function-name> <ows> <function-parameters> <ows> ':' <ows> <return-type> <ows> <function-body>
--
2.44.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/4] docs: spec: remove assignment as expression
2024-04-16 20:17 [PATCH 0/4] docs: spec: constant initialization and assignments ricardo_kagawa
2024-04-16 20:17 ` [PATCH 1/4] docs: spec: refactor grammar specification ricardo_kagawa
2024-04-16 20:17 ` [PATCH 2/4] docs: spec: immediate constant initialization ricardo_kagawa
@ 2024-04-16 20:17 ` ricardo_kagawa
2024-04-16 22:34 ` Johnny Richard
2024-04-16 20:17 ` [PATCH 4/4] docs: spec: postpone assignment operators ricardo_kagawa
2024-04-16 21:58 ` [PATCH 0/4] docs: spec: constant initialization and assignments Carlos Maniero
4 siblings, 1 reply; 10+ messages in thread
From: ricardo_kagawa @ 2024-04-16 20:17 UTC (permalink / raw)
To: ~johnnyrichard/olang-devel; +Cc: Ricardo Kagawa
From: Ricardo Kagawa <ricardo_kagawa@disroot.org>
This commit prevents the use of assignments as expressions, to prevent
chained assignments and the use of assignments inside potential future
`if`, `while` and other statements. However, assignments are still
valid statements.
Signed-off-by: Ricardo Kagawa <ricardo_kagawa@disroot.org>
---
docs/pages/language-specification.md | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/docs/pages/language-specification.md b/docs/pages/language-specification.md
index 8d8544a..724ed67 100644
--- a/docs/pages/language-specification.md
+++ b/docs/pages/language-specification.md
@@ -45,11 +45,8 @@ language.
(* Statements *)
<end-of-statement> ::= ';' | <line-break>
-<common-statement> ::= <variable-definition> | <assignment-expression>
-
-(* Expressions *)
-<expression> ::= <integer-literal> | <variable-name>
-<assignment-expression> ::= <variable-name> <ows> <assignment-operator> <ows> <expression>
+<common-statement> ::= <variable-definition> | <constant-definition> | <assignment>
+<assignment> ::= <variable-name> <ows> <assignment-operator> <ows> <expression>
<assignment-operator> ::= '='
| '*='
| '/='
@@ -62,6 +59,9 @@ language.
| '^='
| '|='
+(* Expressions *)
+<expression> ::= <integer-literal> | <variable-name>
+
(* Identifiers *)
<type> ::= 'u32'
<identifier> ::= (<alpha> | '_') (<alpha> | <digit> | '_')*
--
2.44.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 4/4] docs: spec: postpone assignment operators
2024-04-16 20:17 [PATCH 0/4] docs: spec: constant initialization and assignments ricardo_kagawa
` (2 preceding siblings ...)
2024-04-16 20:17 ` [PATCH 3/4] docs: spec: remove assignment as expression ricardo_kagawa
@ 2024-04-16 20:17 ` ricardo_kagawa
2024-04-16 22:35 ` Johnny Richard
2024-04-16 21:58 ` [PATCH 0/4] docs: spec: constant initialization and assignments Carlos Maniero
4 siblings, 1 reply; 10+ messages in thread
From: ricardo_kagawa @ 2024-04-16 20:17 UTC (permalink / raw)
To: ~johnnyrichard/olang-devel; +Cc: Ricardo Kagawa
From: Ricardo Kagawa <ricardo_kagawa@disroot.org>
This commit temporarily removes the definition of assignment operators
from the grammar, since their corresponding binary operators are still
not in the grammar. The incomplete grammar would be ill defined,
although still syntactically valid.
Signed-off-by: Ricardo Kagawa <ricardo_kagawa@disroot.org>
---
docs/pages/language-specification.md | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/docs/pages/language-specification.md b/docs/pages/language-specification.md
index 724ed67..3cf050e 100644
--- a/docs/pages/language-specification.md
+++ b/docs/pages/language-specification.md
@@ -48,16 +48,6 @@ language.
<common-statement> ::= <variable-definition> | <constant-definition> | <assignment>
<assignment> ::= <variable-name> <ows> <assignment-operator> <ows> <expression>
<assignment-operator> ::= '='
- | '*='
- | '/='
- | '%='
- | '+='
- | '-='
- | '<<='
- | '>>='
- | '&='
- | '^='
- | '|='
(* Expressions *)
<expression> ::= <integer-literal> | <variable-name>
--
2.44.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/4] docs: spec: constant initialization and assignments
2024-04-16 20:17 [PATCH 0/4] docs: spec: constant initialization and assignments ricardo_kagawa
` (3 preceding siblings ...)
2024-04-16 20:17 ` [PATCH 4/4] docs: spec: postpone assignment operators ricardo_kagawa
@ 2024-04-16 21:58 ` Carlos Maniero
4 siblings, 0 replies; 10+ messages in thread
From: Carlos Maniero @ 2024-04-16 21:58 UTC (permalink / raw)
To: ricardo_kagawa, ~johnnyrichard/olang-devel
Thank you so much for your contribution, Ricardo!
Just a few observations:
- In the future patches don't forget to define the
*format.subjectPrefix = PATCH olang*, this is how the olang CI is
triggered. This can be configured once at the repo's *.git/config*.
- We reword your first patch to "docs: spec: make non-terminals more
descriptivedocs: spec: make non-terminals more descriptive" just to
make clear at the short commit message, what the actual change is.
There is a concept we are trying to follow called git recipe history
[1].
Other than that everything is completely amazing! We are glad to
receive your inputs.
Applied!
To git.sr.ht:~johnnyrichard/olang
7cd840e..0046920 main -> main
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/4] docs: spec: refactor grammar specification
2024-04-16 20:17 ` [PATCH 1/4] docs: spec: refactor grammar specification ricardo_kagawa
@ 2024-04-16 22:32 ` Johnny Richard
0 siblings, 0 replies; 10+ messages in thread
From: Johnny Richard @ 2024-04-16 22:32 UTC (permalink / raw)
To: ricardo_kagawa; +Cc: ~johnnyrichard/olang-devel
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/4] docs: spec: immediate constant initialization
2024-04-16 20:17 ` [PATCH 2/4] docs: spec: immediate constant initialization ricardo_kagawa
@ 2024-04-16 22:33 ` Johnny Richard
0 siblings, 0 replies; 10+ messages in thread
From: Johnny Richard @ 2024-04-16 22:33 UTC (permalink / raw)
To: ricardo_kagawa; +Cc: ~johnnyrichard/olang-devel
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/4] docs: spec: remove assignment as expression
2024-04-16 20:17 ` [PATCH 3/4] docs: spec: remove assignment as expression ricardo_kagawa
@ 2024-04-16 22:34 ` Johnny Richard
0 siblings, 0 replies; 10+ messages in thread
From: Johnny Richard @ 2024-04-16 22:34 UTC (permalink / raw)
To: ricardo_kagawa; +Cc: ~johnnyrichard/olang-devel
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 4/4] docs: spec: postpone assignment operators
2024-04-16 20:17 ` [PATCH 4/4] docs: spec: postpone assignment operators ricardo_kagawa
@ 2024-04-16 22:35 ` Johnny Richard
0 siblings, 0 replies; 10+ messages in thread
From: Johnny Richard @ 2024-04-16 22:35 UTC (permalink / raw)
To: ricardo_kagawa; +Cc: ~johnnyrichard/olang-devel
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-04-16 21:58 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-16 20:17 [PATCH 0/4] docs: spec: constant initialization and assignments ricardo_kagawa
2024-04-16 20:17 ` [PATCH 1/4] docs: spec: refactor grammar specification ricardo_kagawa
2024-04-16 22:32 ` Johnny Richard
2024-04-16 20:17 ` [PATCH 2/4] docs: spec: immediate constant initialization ricardo_kagawa
2024-04-16 22:33 ` Johnny Richard
2024-04-16 20:17 ` [PATCH 3/4] docs: spec: remove assignment as expression ricardo_kagawa
2024-04-16 22:34 ` Johnny Richard
2024-04-16 20:17 ` [PATCH 4/4] docs: spec: postpone assignment operators ricardo_kagawa
2024-04-16 22:35 ` Johnny Richard
2024-04-16 21:58 ` [PATCH 0/4] docs: spec: constant initialization and assignments Carlos Maniero
Code repositories for project(s) associated with this public inbox
https://git.johnnyrichard.com/olang.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox